This article explains basic commands for navigation within Linux file system. The diagram below represents (part of) a Linux file system know as Filesystem Hierarchy Standard. A line from one node to a node on its right indicates containment. For example, the student directory is contained within the home directory.

FileSystem Hierarchy Standard direcotry tree

1. When you are working within a shell terminal, you are always operating in a particular directory. To determine which directory you are in, use the pwd command:

student@linuxgym:$ pwd /usr/local/bin 
student@linuxgym:$ cd
student@linuxgym:$ pwd /home/student
student@linuxgym:$

 

2. Your home directory is the directory you are in when you first open the terminal. To go to your home directory from anywhere, just type cd:

student@linuxgym:$ pwd
/usr/local/bin
student@linuxgym:$ cd
student@linuxgym:$ pwd
/home/student
student@linuxgym:$

3. An absolute path name is one beginning with the / character, which signifies the root of the file system tree. Therefore, another way of going to your home directory is:

student@linuxgym:/etc$ cd /home/student
student@linuxgym:$ pwd
/home/student
student@linuxgym:$

4. A relative path is one which starts with the name of a directory connected to the current directory. For example, if you are in the /usr directory, then typing only cd bin (without preceding "bin" with "/") has the following effect:

student@linuxgym:$ pwd
/usr
student@linuxgym:$ cd bin
student@linuxgym:$ pwd
/usr/bin
student@linuxgym:$

and you go to /usr/bin rather than /usr/local/bin or /bin.

5. To go to the directory containing the current working directory (also called the parent directory) type:

student@linuxgym:$ pwd
/usr/bin
student@linuxgym:$ cd ..
student@linuxgym:$ pwd
/usr
student@linuxgym:$

6. The relative pathname of the current working directory is called . (the full stop). Therefore typing:

student@linuxgym:$ pwd
/usr/bin
student@linuxgym:$ cd .
student@linuxgym:$ pwd
/usr/bin
student@linuxgym:$

does not change the current working directory.

ARE YOU LOOKING FOR A LINUX JOB?
Submit your RESUME, create a JOB ALERT or subscribe to RSS feed on LinuxCareers.com.
LINUX CAREER NEWSLETTER
Subscribe to NEWSLETTER and receive latest news, jobs, career advice and tutorials.
DO YOU NEED ADDITIONAL HELP?
Get extra help by visiting our LINUX FORUM or simply use comments below.

You may also be interested in: