Page 1 of 1

CLI: fast switching between directories

Posted: 09 Dec 2013, 12:56
by viking60
When I work with imagemagick I often have to switch between my regular image directory and the work directory (like animations) that contains the animation or whatever.
Since I work with imagemagick in a terminal I need to switch between those two directories a lot - in the CLI.

So for this work process I do the following:

Code: Select all

cd ~/images
cd ~/animations


Now I can switch between these two only by simply entering

Code: Select all

cd -


It is way faster than using arrow up and enter too ( the trouble with that is that you may have entered a lot of other (imagemagick)commands so you will have too look for a while.)

All you need to do is enter cd - and you are in /home/you/images and enter it again and you will be in /home/you/animations.

It is as easy as that +1

cd - will only switch between two directories (which is what we want in this case). You will have to remember to make a space between "cd" and "-" so you might want to make an alias so that cd- works too.
----
If you have this directory that you often want to come back to from anywhere on your command line you can use popd and pushd.

I really should read my logs more often and I am particularly interested in watching my printer so I want to check out cups logs more often.
Here is what I do:

Code: Select all

pushd /var/log/cups


To get there from anywhere you simply type

Code: Select all

popd

You will now be in /var/log /cups
Useful for scripts but since it works only once I have not found it practical in regular CLI work.