I noticed that frequently I have to do something like this:

I am in a path: /very/long/path/1 and I have to go to /another/long/path/ to do some things there. Than I have to come back to my /very/long/path/1. To make things worse sometimes another third path is there and I constantly switch from one to another.

This is not a problem with cd, but is there a way of somehow store this paths and use them?

I am working from command line on some remote host.


The cdargs Install cdargs program is designed expressly for the purpose of managing bookmarks of frequently-visited directories for easy navigation in the shell exactly like you want. It comes with bash shell integration and tab completion on the directories that you have saved.

sudo apt-get install cdargs
. /usr/share/doc/cdargs/examples/cdargs-bash.sh
cd /very/long/path/1
mark path1
cd /another/long/path/
mark path2
cd /yet/another/third/long/path
mark foo
cv path1
cv foo
cv p<TAB> ## tab-completes to "path1/" or "path2/"

The bookmarks that you create are saved by cdargs in its own configuration file, so they are automatically carried over from one shell session to the next and available the next time you log in or open a terminal.

It even comes with an interactive curses mode to browse your complete list of bookmarked directories. Just run cv or cdargs with no arguments and it will show a list of bookmarked directory paths that you can select using the arrow keys or vi-style hjkl.

To activate cdargs for your shell environment automatically, simply source /usr/share/doc/cdargs/examples/cdargs-bash.sh from your ~/.bashrc or otherwise arrange for it to be loaded in every bash interactive shell. For example,

cp /usr/share/doc/cdargs/examples/cdargs-bash.sh ~/.bashrc-cdargs
echo '. ~/.bashrc-cdargs' >> ~/.bashrc

Look at the pushd and popd commands. You can find information on Google but basically they are like cd with a stack like memory.

  • 1
    +1, and an example or little more explanation about pushd and popd commands would be better. – Avinash Raj May 15 '14 at 3:46

You can use cd - to swith to last visited directory. It will save you a lot of time.


You could always add an alias.

alias big='cd /very/long/directory/goes/here'

Then just type big

For more permanent alias:

How do I create a permanent Bash alias?

Since the pushd and popd example got more upvotes, but the guy didn't explain it :)

Basically when you do pushd it makes a list of directories you can put into it. (If you have any programming background, it is very similar when you pop an item from a list, if not I will explain)

So if you do pushd ~/Music you just added a directory to a list from which you can access. You can also do pushd dir to add your current(working) directory to this list. When you use the pushd command alone, it will cycle through the list (it is actually technically stack).


So if you want to add 3 directories. It would look like this

user@user: pushd /really/long/dir/1/ <--User input

/really/long/dir/1/ <---Output

user@user: pushd /really/long/dir/2/ /really/long/dir/1/ /really/long/dir/2/ user@user: pushd /really/long/dir/3/ /really/long/dir/1/ /really/long/dir/2/ /really/long/dir/3/

These will all be added like so. When you use pushd it will go to the next directory on the list, and push the first to the end. So the list would start 1,2,3 and go 2,3,1 --> 3,1,2 --> 1,2,3 .

popd deletes the directory at the front of the list, and moves you to the first directory of the new list. So lets do this with 4 directories.(assuming popd command is used each time)


(start with 1,2,3,4, in any directory)

2,3,4 (You are in directory 2)

3,4 (You are in directory 3

4 (You are in directory 4)

Empty list (No change of directory)

  • sounds cool. Is there a way to see a list of all aliases created in the system? – Salvador Dali May 15 '14 at 5:02
  • 1
    @SalvadorDali Just type alias and you'll see the active aliases. – Oli May 15 '14 at 6:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.