Relative and Absolute Paths
Learn about relative and absolute paths in a Linux environment for faster navigation.
We'll cover the following
Relatives paths
So far, we’ve been navigating using relative paths. That means we’ve been specifying the destination relative to our current working directory or our current location on the filesystem. When we’re at the filesystem’s root and type cd var
, the var
directory is something we can see with the ls
command. We and the var
directory are in the same location on the filesystem, and the command we specified said, “Switch to the var
directory that’s in the same folder that I’m currently working in.”
Absolute paths
We can navigate the filesystem much more quickly by using the entire path to a directory from the filesystem’s root. Let’s navigate to the /usr/bin
directory. We have to go to the /usr
folder first and then open the bin
directory in a GUI. But the cd
command can take entire file paths so that we can jump to the /usr/bin
directory in a single command.
$ cd /usr/bin
This command says:
- Go to the filesystem’s root.
- Go into the
usr
folder. - Go into the
bin
folder.
Try moving around to a few locations this way. Navigate to the /usr/lib
directory, and then navigate back to the /var
directory:
$ cd /usr/lib
$ pwd
$ cd /var
$ pwd
Use the terminal below to try these commands.
Get hands-on with 1400+ tech skills courses.