CLI: fast switching between directories

Every day solutions to every day challenges. + Brilliant stuff

Moderators: b1o, jkerr82508

Forum rules
Please feel free to post your tip it does not have to be advanced. Also ask questions directly related to the tip here. But do not start new threads with questions or ask for help here. That is what the help section is for. forum rules: http://bjoernvold.com/forum/viewtopic.php?f=8&t=568
User avatar
viking60
Über-Berserk
Posts: 9351
Joined: 14 Mar 2010, 16:34

CLI: fast switching between directories

Postby viking60 » 09 Dec 2013, 12:56

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.
Manjaro 64bit on the main box -Intel(R) Core(TM) i7 CPU 920 @ 2.67GHz and nVidia Corporation GT200b [GeForce GTX 275] (rev a1. + Centos on the server - Arch on the laptop.
"There are no stupid questions - Only stupid answers!"

Return to “Tips & Tricks”