Navigating  filesystem in the Linux terminal - Part1

Navigating filesystem in the Linux terminal - Part1

·

3 min read

As a Linux user, navigating the filesystem is a fundamental skill that allows you to explore, locate, and manipulate files and directories.

Also understanding how to efficiently move through the directory structure and access specific locations is crucial for effective command-line usage.

In this two-part series article, we discuss some common commands associated with navigating the Linux file system hierarchy, while also covering the following topics:

  • Linux Filesystem Hierarchy

  • Listing Files and Directories

  • Navigating Directories

  • Working with Paths

Linux File System Hierarchy(FHS)

Unlike other operating systems, Linux organizes its files and directories in a hierarchical structure. Understanding the directory structure can be daunting and discussing it in detail goes beyond the scope of this article.

However, we take an overview of the overall Linux file structure while closely looking at some of the most important directories.

Linux File System Hierarchy(FHS)

The following table contains an explanation of what important directories are used for.

LocationPurpose
/ (Root)The main folder is where all other folders and files are kept in the Linux system.
/bin (Binaries)A folder that holds important programs for basic tasks on the computer.
/boot (Boot Files)Contains files needed to start up the computer, like the main program and settings.
/dev (Devices)A folder with files that let the computer talk to connected devices like printers or keyboards.
/etc (Configuration Files)Keeps files with settings for different parts of the computer system.
/home (User Home Directories)Each person using the computer has a special folder here to keep their stuff.
/lib (Libraries)A folder that holds extra tools used by different programs.
/media (Removable Media)When you put something like a USB stick into the computer, it appears here so you can access its files.
/opt (Optional Packages)A folder where you can install extra programs that are not already on the computer.
/tmp (Temporary Files)A place where the computer puts files it only needs for a little while, and then gets rid of them.
/usr (User Programs)A folder where programs, books, and other things for users are kept.
/var (Variable Data)A folder for things that change often, like logs of what the computer has been doing or temporary files it creates

Listing Files and Directories(ls,cd,pwd,tree,Find)

We take a look at some commonly used commands in listing directories and files.

ls - command

syntax: ls

The "ls" command(ls stands for list) is used to list files and directories in the current directory. Here are some useful options:

  • "ls": Lists files and directories in a simple format.

  • "ls -l": Displays a detailed list with file permissions, ownership, size, and modification time.

  • "ls -a": Shows all files, including hidden files that start with a dot.

  • "ls -lh": Provides a human-readable format with file sizes in a more readable form.

  • "ls -R": Recursively lists files and directories, including all subdirectories.

cd - command

The "cd" command(cd stands for change directory) allows you to navigate to a different directory. Here are a few examples:

  • "cd" or "cd ~": Takes you to your home directory.

  • "cd /path/to/directory": Changes the current directory to the specified path.

  • "cd .. ": Moves up to the parent directory.

  • "cd -": Returns to the previous directory you were in.

pwd - command

The "pwd" command(pwd stands for Print Working Directory) displays the current directory's full path.

tree - command

The "tree" command visually displays the directory structure in a tree-like format.

find - command

The "find" command allows you to search for files and directories based on different criteria, such as name, size, or type.