Home » Linux

Navigating Linux File System

Here, we are going to learn about Linux File System Navigation, some of the basic commands, absolute pathnames and relative pathnames.
Submitted by Vipin Bailwal, on September 20, 2018

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.

Navigation in Linux

Fig. 1: The contents of Root Directory.

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.

pwd command

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.

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

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".

Absolute Pathnames

Relative Pathnames

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

Absolute Pathnames

(b) Using relative pathname

relative Pathnames

A 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.

A shortcut to home directory 1

A shortcut to home directory 2

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.





Comments and Discussions




Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.