How To Change Directory In Linux Terminal

cd Command in Linux: Syntax & Options

The cd command (change directory) is one of the most basic Linux commands. It is used to switch over to a different directory from your current directory throughout the file system. The basic syntax to use the cd command is: In the above syntax, you can specify the as either the absolute path, where the paths start from the root directory, or as a relative path, where the paths start from the current working directory. Some of the common options to pair with the Linux cd command are:

Change Directory in Linux Using Absolute Path

As mentioned above, the complete path is described right from the root directory. This method is easier for beginners to learn but entering the complete path becomes cumbersome to change into a directory that’s buried deep in your Linux file system. Let’s say you need to access the Documents directory inside the home directory. The complete path will become: To change inside the Downloads directory using the absolute path. Your shell prompt will now display the newly changed path.

Change Directory in Linux Using Relative Path

While the absolute path works fine for the cd command to change the directory inside the Linux file system, the path tends to become long for the directories that are buried deep inside the system. This is where the relative path comes into play. In the relative mode, the path originates from the current working directory. The current directory is specified as a single dot “.” and the parent directory as double dots “..” here. So if you are in the Documents directory, and you need to access the Downloads directory inside the Home directory, the path becomes: Seems complicated? The “..” climbs up the directory structure to the Home directory, and then, it will search for the Downloads directory. When found, it changes to the Downloads directory in the Linux Terminal. To switch over to the bin directory inside the user directory, use this: Fun Fact: You can use a series of “..” to climb up to the root directory and then travel to any directory of your choice. This is known as a “Local File Inclusion” (LFI) Vulnerability and is often used to access sensitive files like the /etc/passwd.