cd – change directory

When navigating the filesystem tree, changing your current directory is one of the basic actions.

In Unix, changing your current directory is accomlpished by the cd command.

Changing directory in Unix

The cd command syntax is very simple: just specify the directory you'd like to navigate to. At any moment of your navigation, feel free to use the pwd command to confirm your current directory:

ubuntu$ pwd
/home/greys
ubuntu$ cd /etc
ubuntu$ pwd
/etc

In this example, you can see how initially I was in my home directory, /home/greys, and then changed the directory to /etc.

If for some reason you can't change the directory, an error message will be shown:

ubuntu$ cd /tmp/protected/
bash: cd: /tmp/protected/: Permission denied

As you can probably tell from the error message, the problem is directory permissions. If we use the ls command to verify access permissions, we can see that in my example the /tmp/protected directory belongs to root, and only root can access it:

ubuntu$ ls -ald /tmp/protected/
drwxr-xr--    2 root     root         4096 Mar 25 09:36 /tmp/protected/

See also:

Share and Enjoy

  • Facebook
  • Twitter
  • Delicious
  • LinkedIn
  • StumbleUpon
  • Add to favorites
  • Email
  • RSS