17 April 2013

Navigate faster with these CD Command Tricks

9 comments

If you are a Terminal freak or use terminal to do most of your task, then it is obvious that you are frequently using cd Command to navigate from one directory to another. Here are some cd tricks which helps you to navigate much more faster and will boost your productivity.

Trick 1:

Move to your home directory from anywhere: cd (without any argument) and cd ~ (Tilda) commands are used to move to user's home directory from any directory in the file system.

$ pwd
/etc/apache2
$ cd
$ pwd
/home/sandeep

$ pwd
/etc/apache
$ cd ~
$ pwd
/home/sandeep

Trick 2:

Toggle between last two directories: cd - (minus) command is used to toggle between last two visited directories.

$ pwd
/home/sandeep
$ cd /etc/apache2
$ pwd
/etc/apache2

$ cd -
$ pwd
/home/sandeep
$ cd -
$ pwd
/etc/apache2

Trick 3:

Move to parent directory: cd .. (Dot Dot) is used to move to the parent directory of the current directory.

$ pwd
/home/sandeep
$ cd ..
$ pwd
/home

$ cd /etc/apache2
$ pwd
/etc/apache2
$ cd ../..
$ pwdcd *
/

Trick 4:

cd * : This command can be useful if first file is a directory in your current working directory.

$ ls -l
drwxr-xr-x 5 rajkumar rajkumar 4096 Jan 20 14:54 bootstrap
drwxrwxr-x 7 rajkumar rajkumar 4096 Mar 29 13:15 Calibre Library

$ cd *
$ pwd
/home/sandeep/bootstrap

Note: If first file is not a directory then this command doesn't work.

Trick 5:

cd !$ : Sometimes when you create a new directory, you may cd to the new directory immediately to perform some work. You have to use directory name with cd command to move to that directory, this can be sometime tedious if you have to move deep inside the directory. Above command helps you to move faster to the newly created directory.

$ mkdir sandeep
$ cd !$
cd sandeep
$ pwd
/home/sandeep/sandeep

$ mkdir very/long/directory/structure
$ cd !$
very/long/directory/structure
$ pwd
/home/sandeep/very/long/directory/structure

Trick 6:

Consider a scenario If you are frequently moving to subdirectories of a specific parent directory like/var/www, you can set the CDPATH to the parent directory and perform cd to the subdirectories without giving the parent directory path.

$ pwd
/home/sandeep
$ ls -l /var/www
drwxrwxr-x 3 rajkumar rajkumar 4096 Dec 25 18:52 antipattern
drwxrwxr-x 3 rajkumar rajkumar 4096 Mar 1 23:40 Backup
drwxr-xr-x 8 rajkumar rajkumar 4096 Jan 28 22:30 CI
drwxr-xr-x 6 rajkumar rajkumar 4096 Sep 28 2012 CodeIgniter_2.1.2

$ CDPATH=/var/www
$ cd Backup
/var/www/Backup

$ pwd
/var/www/Backup

Note: To make this change permanent add CDPATH=/var/www to your ~/.bash_profile.

That's it.
Hope you Enjoyed the Post.


If You Liked This Post Please Take a Time To Share This Post

You May Also Like...

9 comments:

  1. Thank you great tips! Especially the switching with cd - . I didn't know that. Dirstack pushd popd dirs plus this is extremely useful!

    ReplyDelete
  2. The article has genuinely peaks my interest. I’m going to bookmark your web page and maintain checking for new celebrity jacket details. I am looking for some good blog sites for studying. I was searching over search engines and found your blog site.

    ReplyDelete
  3. This is a really great post, I like Joker 2019 suit I am interested in reading this post.

    ReplyDelete
  4. Such a very useful article. Very interesting to read this article.I would like to thank you for the efforts you had made for writing this awesome article.
    Titans Gar Logan Jacket

    ReplyDelete
  5. more appreciating blog! Great internet site! It looks extremely good! Maintain a good job!| you are rocking man…!

    ReplyDelete
  6. It's a control bargain. In the event that you don't feel in charge, at that point you feel discouraged, restless, confounded, confiscated. So.... how could it be that you can pick up control? furuno marine radio You can do that by doing anything basic which places you in charge - in any event, doing the dishes - playing a computer game.

    ReplyDelete
  7. You have made some good points here. s05 jake taylor leather jacket I looked on the internet for the issue as well as found most people will certainly accompany with your website.

    ReplyDelete
  8. I appreciate the effort you put into crafting your content, it's evident that you're passionate about what you do. CPS Test turned my casual gaming session into a competitive frenzy; I even shared my scores on social media to see how my friends measure up!

    ReplyDelete