In this chapter, we’ll cover the basics of navigating the Linux filesystem. You’ll learn how to move between directories, list their contents, and understand your current location in the filesystem.
Before we dive into commands, let’s take a moment to understand the Linux filesystem. Think of it as a tree with branches. At the very top is the root directory, represented by a single forward slash (/). Everything else—your files, folders, and even other disks—branches out from there.
Here’s a simplified view of a typical Linux filesystem:
/
├── home
│ └── user
│ ├── Documents
│ ├── Downloads
│ └── Pictures
├── etc
├── var
└── binYour home directory (/home/user) is where your personal files live. This is where you’ll spend most of your time.
Let’s start with the essential commands for moving around the filesystem.
pwd: Print Working Directory This command tells you where you are in the filesystem. It’s like asking, “Where am I?”$ pwd /home/user
cd: Change Directory This command lets you move to a different directory. Think of it as saying, “Take me to this folder.”
Documents directory:$ cd Documentscd with no arguments: $ cdTo move up one level (to the parent directory), use ..
$ cd ..
ls: List Directory Contents This command shows you what’s inside a directory. It’s like opening a folder and peeking inside.
$ ls Documents Downloads Music PicturesDownloads)$ ls Downloads file1.txt file2.zipWhen navigating, you can use either absolute paths or relative paths: - Absolute paths start from the root directory (/). For example: $ cd /home/user/Documents
Relative paths start from your current location. For example: $ cd Documents
Pro Tip: Use the Tab key to auto-complete directory and file names. It saves time and reduces typos!
Here are a few special directories you should know: -
~ (Tilde): Represents your home directory. For example: $ cd ~
is the same as:$ cd /home/user.(Dot): Represents the current directory. .. (Double Dot): Represents the parent directory.
Navigating the Linux filesystem can be streamlined with modern tools that enhance the traditional ls and cdcommands. Tools like exa and lsd offer more readable and visually appealing directory listings with colorized output and icons, making it easier to identify file types and permissions at a glance.
For a tree-based view, broot provides an interactive file explorer within the terminal, allowing you to navigate directories, preview file contents, and perform operations efficiently.
When searching for files, fzf offers a command-line fuzzy finder that lets you quickly locate files by typing partial filenames, and integrating it with your shell can enhance your command history search. Additionally, zoxideserves as an intelligent cd alternative, learning your frequently visited directories to allow quick navigation with minimal input.
# Install exa
$ sudo apt install exa
# Use exa for a detailed directory listing
$ exa --long --icons
# Install lsd
$ sudo apt install lsd
# Use lsd for a detailed directory listing
$ lsd --long --icon-theme fancy
# Install broot
$ sudo apt install broot
# Launch broot
$ broot
# Install fzf
$ git clone --depth 1 https://github.com/junegunn/fzf.git ~/.fzf
~/.fzf/install
# Use fzf to search for files
$ fzf
# Install zoxide
$curl -sS https://raw.githubusercontent.com/ajeetdsouza/zoxide/main/install.sh | sh
# Add a directory to zoxide
$ zoxide add /path/to/directory
# Navigate to a directory using zoxide
$ z /path/to/directoryWhile the command line is incredibly powerful, managing files and directories using commands like ls, cd, and cp can sometimes feel tedious. This is where terminal-based file managers come in. These tools provide a more visual and interactive way to navigate and manage files directly in the terminal. Let’s explore two popular options: Midnight Commander and Double Commander.
Midnight Commander (MC) is a text-based file manager inspired by the classic Norton Commander. It has been around since the 1990s and provides a two-pane interface for easy file navigation and management. MC is lightweight, customizable, and packed with features like a built-in file editor, viewer, and support for archives (e.g., .zip, .tar). It also supports mouse input in modern terminals, making it more user-friendly.
$ sudo apt install mc # Debian/Ubuntu $ sudo dnf install mc # Fedora$ mcDouble Commander is a cross-platform file manager inspired by Total Commander. It’s available for Linux, Windows, and macOS and offers a dual-pane interface similar to Midnight Commander. It also includes features like tabbed browsing, plugin support, and extensive customization options.
$ sudo apt install doublecmd-qt # Debian/Ubuntu $ sudo dnf install doublecmd # Fedora$ doublecmdTerminal-based file managers like MC and Double Commander are efficient and lightweight, making them ideal for managing files without leaving the terminal. They offer keyboard shortcuts for faster operations compared to using ls and cp, and they include built-in tools for viewing, editing, and archiving files. These tools are also customizable with themes and keybindings, and they work seamlessly over SSH, making them perfect for remote server management.
However, they do have a learning curve, as users need to learn new shortcuts and navigation methods. They also lack the visual appeal of modern GUI file managers, and while some support mouse input, it’s not as seamless as in graphical tools. Additionally, tasks like bulk image previews or complex file operations are better handled by GUI tools.
While Midnight Commander is a classic, there are modern alternatives that offer different features or user interfaces:
$ sudo apt install ranger # Debian/Ubuntu $ sudo pacman -S ranger # Arch/Manjaro$ ranger$ sudo apt install nnn # Debian/Ubuntu $ sudo pacman -S nnn # Arch/Manjaro$ nnn$ lfTerminal-based file managers are ideal for:
Remote Servers: Managing files over SSH without a GUI.
Lightweight Systems: Systems with limited resources or no graphical interface.
Power Users: Users who prefer keyboard-driven workflows and want to stay in the terminal.
Terminal-based file managers like Midnight Commander and Double Commander bridge the gap between the raw power of the command line and the convenience of graphical file managers. They’re perfect for users who want a more interactive way to manage files without leaving the terminal. While they may not replace graphical tools for all tasks, they’re invaluable for remote server management, lightweight systems, and power users who prefer keyboard-driven workflows.
Let’s put your new skills to the test. Open your terminal and try the following:
pwd to check your current location.2. Use cd to navigate to your Documents directory.
3. Use ls to list its contents.
4. Use cd .. to move back to your home directory.
5. Use cd ~ to return to your home directory (if you’re not already there).
6. Install Midnight Commander and explore its features.
7. Try Double Commander and compare it to MC.
8. Use a terminal file manager to organize files on a remote server.
That’s it for Chapter 2! You’ve now learned how to navigate the Linux filesystem like a pro. In the next chapter, we’ll explore how to view files and directories in more detail. Until then, practice moving around and getting comfortable with the commands.