Tuesday, December 26, 2006

Unix Change Directory Commands

In unix, the cd command is used to change directories. For example, cd /tmp will put you in the /tmp directory.

Here are some tips/tricks for cd:

cd by itself or cd ~ will always put you in your home directory.

cd ~username will put you in username's home directory.

cd dir (without a /) will put you in a subdirectory. for example, if you are in /usr, typing cd bin will put you in /usr/bin, while cd /bin puts you in /bin.

cd .. will move you up one directory. So, if you are /usr/bin/tmp, cd .. moves you to /usr/bin, while cd ../.. moves you to /usr (i.e. up two levels). You can use this indirection to access subdirectories too. So, from /usr/bin/tmp, you can use cd ../../local to go to /usr/local.

cd - will switch you to the previous directory. For example, if you are in /usr/bin/tmp, and go to /etc, you can type cd - to go back to /usr/bin/tmp. You can use this to toggle back and forth between two directories.

3 comments:

Amy said...

Thank you. This blog was very helpful. :)

Ahmed Abbas said...

thanks

rbcalonzo said...

Thanks :)