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 accomplished by the cd command.

cd – change 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][pwd-command] to confirm your current directory:

ubuntu$ pwd
ubuntu$ cd /etc
ubuntu$ pwd

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

cd .. command

In Unix and Unix-like operating systems, each directory contains two special entries:

  • file “.” (dot) means the current directory
  • file “..” (two dots) means the parent directory

Using the .. entry you can change to the parent directory (the one above your current directory), even without knowing the exact name of that parent directory.

For example:

ubuntu$ pwd
ubuntu$ cd ..
ubuntu$ pwd
cd permission denied

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

Keep Learning with Me

Follow me on Facebook and Twitter or jump into Telegram chat!:
Recommended Software
I use Brave browser, it's awesome: Brave Browser I'm also a fan of SetApp for macOS: SetApp for macOS
IT Consultancy
I'm a principal consultant with Tech Stack Solutions. I help with cloud architectrure, AWS deployments and automated management of Unix/Linux infrastructure. Get in touch!
Recent Articles
18 Jun 2021

CentOS 8.4 Released

17 Jun 2021

yum/dnf Package Manager Basics

07 Jun 2021


Recent Tweets