Home »
Linux
Navigating Linux File System
By IncludeHelp Last updated : October 19, 2024
Why would you want to learn?
Linux is probably the most used operating system when it comes to development. For a developer, Linux provides all the required tools. Learning how to navigate the Linux file system can really benefit if you plan on using Linux as your primary operating system or for development purpose. The Linux command line is a very powerful tool that makes it easy and fast to access files on the system.
The Linux File System
Linux organizes its files in a hierarchical directory structure. The files are organized in a tree-like manner. The directories may contain files and other directories. The first directory in the Linux file system is the root directory (named as a /). The root directory is the parent of all other directories in the file system. It contains files and sub-directories, which contain more files and sub-directories and so on.
Fig. 1: The contents of Root Directory.
Linux Basic Commands
1. pwd: print the name of the current working directory on the terminal
To check which directory we are currently working in, we can use the "pwd" command. This command prints the absolute path of the current/working directory.
When we log in to the system, our current working directory is set to our home directory. Each user is assigned its own home directory where he writes his files.
2. ls: list the contents of the current working directory
To see what files we have in the current working directory we can use the "ls" command.
3. cd: change directory
To change our current working directory we use "cd" command. To change the current working directory type "cd" followed by the pathname of the new directory to which you want to go. A pathname is a route that we take to reach a particular directory. Pathnames can be specified in two ways:
Absolute Pathnames in Linux File System
An absolute pathname begins with the root directory and follows the tree structure until the path to the desired directory is reached. For example, if I want to reach the directory bin in the usr directory which is a part of the root directory, the absolute pathname would be "/usr/bin".
Relative Pathnames in Linux File System
Unlike absolute pathnames which start from the root directory, Relative pathnames start from the working directory. Linux uses two particular symbols to represent the current directory and its parent directory in the file system. These are the "." and ".." symbols.
The "." symbol refers to the working directory and the ".." symbol refers to the parent directory of the working directory. Let's see this.
pwd : /usr/bin
Let's change our working directory i.e., /usr/bin to its parent directory which is /usr. We can do this as:
(a) Using absolute pathname
(b) Using relative pathname
Shortcut to Home Directory
The "~" symbol represents the home directory of the user. So we can use this symbol to directly go to the home directory or list its contents with ls.
Summing Up
In this article we saw how shell treats the Linux File System. We also learned about absolute and relative pathnames and the basic commands that are used move about the file system.