This Blog is intended to collect information of my various Intrests,pen my opinion on the information gathered and not intended to educate any one of the information posted,but are most welcome to share there view on them

Sunday, January 22, 2012

6 Awesome Linux cd command Hacks – Productivity Tips

Hack #1: Use CDPATH to define the base directory for cd command

If you are frequently doing cd to subdirectories of a specific parent directory, you can set the CDPATH to the parent directory and perform cd to the subdirectories without giving the parent directory path as explained below.

[ramesh@dev-db ~]# pwd
/home/ramesh
[ramesh@dev-db ~]# cd mail
-bash: cd: mail: No such file or directory
[Note: This is looking for mail directory under current directory]
[ramesh@dev-db ~]# export CDPATH=/etc
[ramesh@dev-db ~]# cd mail
[Note: This is looking for mail under /etc and not under current directory]
[ramesh@dev-db /etc/mail]# pwd
/etc/mail

To make this change permanent, add export CDPATH=/etc to your ~/.bash_profile

This hack can be very helpful under the following situations:

Oracle DBAs frequently working under $ORACLE_HOME, can set the CDPATH variable to the oracle home

Unix sysadmins frequently working under /etc, can set the CDPATH variable to /etc

Developers frequently working under project directory /home/projects, can set the CDPATH variable to /home/projects

End-users frequently accessing the subdirectories under their home directory, can set the CDPATH variable to ~ (home directory)

Hack #2: Use cd alias to navigate up the directory effectively

When you are navigating up a very long directory structure, you may be using cd ..\..\ with multiple ..\’s depending on how many directories you want to go up as shown below.

Instead of executing cd ../../../.. to navigate four levels up, use one of the following alias methods:Navigate up the directory using ..n : In the example below, ..4 is used to go up 4 directory level, ..3 to go up 3 directory level, ..2 to go up 2 directory level. Add the following alias to the .bash_profile and re-login.

Navigate up the directory using only dots: In the example below, ….. (five dots) is used to go up 4 directory level. Typing 5 dots to go up 4 directory structure is really easy to remember, as when you type the first two dots, you are thinking “going up one directory”, after that every additional dot, is to go one level up. So, use …. (four dots) to go up 3 directory level and .. (two dots) to go up 1 directory level. Add the following alias to the .bash_profile and re-login for the ….. (five dots) to work properly.

Navigate up the directory using cd followed by consecutive dots: In the example below, cd….. (cd followed by five dots) is used to go up 4 directory level. Making it 5 dots to go up 4 directory structure is really easy to remember, as when you type the first two dots, you are thinking “going up one directory”, after that every additional dot, is to go one level up. So, use cd…. (cd followed by four dots) to go up 3 directory level and cd… (cd followed by three dots) to go up 2 directory level. Add the following alias to the .bash_profile and re-login for the above cd….. (five dots) to work properly.

At this stage, the directory stack contains the following directories:

/tmp/dir4
/tmp/dir3
/tmp/dir2
/tmp/dir1

The last directory that was pushed to the stack will be at the top. When you perform popd, it will cd to the top directory entry in the stack and remove it from the stack. As shown above, the last directory that was pushed into the stack is /tmp/dir4. So, when we do a popd, it will cd to the /tmp/dir4 and remove it from the directory stack as shown below.

About Me

Hi This is Suresh Kumar Pakalapati . I am a person who is positive about every aspect of life. There are many things I like to do, to see, and to experience. I like to feel the music flowing on my face, I like good books and romantic, action,cartoon movies. I like the land and the nature, And, I like to keep smile on my face. I always wanted to be a great and successful person in the world and I know it is needed More and More education, More work, Success Never come in a short Time.....