How to get around the console and be an expert

cd as an expert

Let us start with the simplest and see that cd is a bit more complex than it seems. Many people know of the auto-bash, which is to type the directory name and press Tab to complete the console directory (if there are several possibilities, otherwise we would have to press Tab to see them twice). It is also very common to use relative paths: if we are in / home / zootropo and we want to move / home / zootropo / videos do not need to write the second route in its entirety, but we can just type cd videos. Even novice is normal to see shortcuts like using cd .. to move to the directory and cd cd ~ or to move to the directory.

What is less common, and useful for the issue at hand is the use of cd -. This flag is not useful as anything other than move to the last directory you were.

  Genua zootropo @: ~ $ cd / etc/X11 /
  Genua zootropo @: / etc/X11 $ cd
  Genua zootropo @: ~ $ cd --
  / etc/X11
  Genua zootropo @: / etc/X11 $ pwd
  / etc/X11

In this way we can move quickly between two directories.

On the other hand, if we need to move to a directory just a moment to run a command and then continue working in the current directory, we could also use & to run two commands, one after another, conditionally (and shorted)

cd / etc/X11 / & & cat xorg.conf

and surround him with parentheses, which makes the commands are executed in a sub

(cd / etc/X11 / xorg.conf & cat)

this will run the command in a different sub, so the CD does not affect us, and it will be as if we had never moved.

But what if we want to move between different directories? What can we do if we want to move, for example, when we visited last directory? The combination pushd, popd and dirs, it gives us a viable alternative.
pushd, popd and dirs

pushd cd works as a normal, moving the specified directory, but also, as its name suggests, it introduces a directory stack.

pushd / etc/X11 /

popd also works as a cd, but the directory that is what moves us out of the stack, and since the stack is a LIFO (Last In, First Out or whatever it is, the last to enter the drawn first) to write this command will move us to the last directory added to the stack.

popd

It is also possible to indicate which item we want to use the battery through an index. For example:

popd +2

draw the third element (the index of the first element is 0). We may also use negative indices, such as -2, counting backwards.

Finally dirs we used to print the contents of the stack:

Genua zootropo @: / etc/X11 $ dirs
  / etc/X11 ~

dir dirs command also can pass an index to print only the directory selected by the index.

The disadvantage of using pushd and popd is that every time we make a directory popd is removed from the stack and use it again if we have to go back to save on the stack, which runs counter to the speed we want and which prompted us to use them first.

There is an alternative that is to take advantage of the feature of indexing dirs. The command

dirs +0

show the first element of the stack.

Just use this directory as an argument to cd to be able to move the directories stored without being deleted from the stack:

+0 `cd` dirs

However, for some strange reason, when we select the directory with dirs is the home directory, which is stored as ~ This little trick does not work, but we should use the flag-l dirs to display the full path of the directory home instead of ~.

dirs-l `cd` +0

We could save having to type the flag-l with a nickname, and even create aliases as

alias cd = "pushd"
  cd1 alias = "cd` dirs-l `+1"

so that we move to write the penultimate cd1 introduced our directory cd-pushd.

However, there are simpler alternatives, such as CDargs.
CDargs

CDargs is in the Ubuntu repositories, so you install this distro is as simple as typing:

sudo aptitude install cdargs

It is also necessary to add functions to bash already created the application that comes with editing. Bashrc:

gedit ~ /. bashrc

and adding the following line, which is a source of the file (make sure the file is installed on the route and modify the line properly if it does not)

source / usr / share / doc / cdargs / examples / cdargs-bash.sh

Restart the console and can start playing.

If the command

cv

on the console, will launch the graphical interface of ncurses CDargs, a small file browser mode console.

CDargs

First select the directory that we are concerned with the up and down arrows, with Page Up and Rollback page, Home and End, or pressing the associated number. If you just want to make a cd to that directory, press enter. If we want to make a cd to a directory that is contained within the selected directory, click the right arrow to display its contents CDargs, and finally, if we want to move a directory, click the left arrow. To exit the interface without doing anything, press the key 'q'. If you want to see hidden files, click the button '..'

CDargs also includes a marker system. We use it to move to the directory you want to add to our favorites and write

cadiz label

For example:

cd / home / zootropo / videos
  cadiz vid

Then just write

cv label

to move to the directory to store bookmarks in the label.

We can see the markers we have developed since the GUI CDargs pressing the Tab key to switch between the mode and manner of browser bookmarks.

Finally, you might be interested to look at the file manager so console, such as GNU Midnight Commander

sudo aptitude install mc