1. Home
  2. Linux

How to browse the hard drive from the terminal in Linux

The fastest way to browse the hard drive from terminal in Linux is with the ls and cd command. The primary reason why it’s a good idea to use this method to browse your Linux hard drive quickly is that both of these commands come standard with the Linux desktop. There is no software to install, and the whole process of moving through the file system is very straightforward. Here’s how it works.

The ls and cd commands

Ls – shows the contents of any given directory. It can also be made to show hidden files with ls -a.

Cd – can change the working directory of the terminal shell to another directory.

So, for example, if you need to view a file in the “/opt” folder, you would first use the cd command to move to the “/opt” folder from the working directory the terminal starts in (home).

cd /opt

Once inside of the “/opt” directory, the ls command can be called in to show the contents of the folder, exposing the various files and sub-directories that you may want to access.

ls

It is also possible to browse backward with the cd command. For example, if you need to move from “/opt/sub-folder-1/” back one directory to “/opt” cd .. can be used.

cd ..

Terminal based file manager

The ls/cd browsing method is very basic and will allow users to move to through a Linux file system with ease, but it doesn’t offer advanced features such as the quick opening of files, or fast navigation. Also, typing out cd/ls over and over to move through a hard drive to access specific files and folders can be very tedious, and not the best method for impatient Linux users.

Another way to browse the Linux file system in the terminal is with a text-based file manager such as Midnight Commander or Ranger.

Midnight Commander

Midnight Commander is the go-to text-based file manager for many Linux users who need to browse a Linux file system through a terminal window. The reason it’s so popular? The user interface is colorful, easy to understand, and even Linux users who are new to the platform can figure out how to use it very quickly!

Install Midnight Commander

Midnight Commander has been around for quite a while in the Linux world, so virtually every distribution has it in their software repositories. To install it, open up a terminal window with Ctrl + Alt + T or Ctrl + Shift + T on the keyboard. Then, follow the command-line instructions below to get the app installed.

Ubuntu

sudo apt install mc

Debian

sudo apt-get install mc

Arch Linux

sudo pacman -S mc

Fedora

sudo dnf install mc

OpenSUSE

sudo zypper install mc

Browsing with MC

With the Midnight Commander application installed, launch it from the terminal by entering the mc command.

mc

Once you open up the Midnight Commander app, a text-based file manager UI will appear on screen with two panels. From here, use your mouse (if you have one) and click on the folder you’d like to access. To go back a folder, click on “/..”.

To access some of the more advanced Midnight Commander functions press Alt + 2, select the option you want to execute in the menu with the mouse or up/down arrows, and press Enter to select your choice.

To access any of the special operations in the bottom bar of Midnight Commander, press Alt + 1 – 10.

Ranger

Ranger is another popular file manager for the Linux terminal. It lacks a lot of the more advanced features that Midnight Commander has, but it’s perfect for browsing files and folders on Linux through the command line.

Installing Ranger

Ranger is a well-known text-based file manager, so it’ll be easy to get going on most Linux operating systems. To install it on your computer, open up a terminal window with Ctrl + Alt + T or Ctrl + Shift + T and follow the command-line instructions below that match the OS you use.

Ubuntu

sudo add-apt-repository universe
sudo apt update
sudo apt install ranger

Debian

sudo apt-get install ranger

Arch Linux

sudo pacman -S ranger

Fedora

sudo dnf install ranger

OpenSUSE

sudo zypper install ranger

Browsing with Ranger

To browse your Linux hard drive from the terminal with Ranger, start by writing the ranger command in a terminal, and it’ll launch in your home directory (~).

ranger

With Ranger open, use the left arrow key to go back a folder level, or the right arrow key to open a folder. Use the up arrow or down arrow to highlight any file you’d like to access, and Ranger will instantly launch it in the default program, or display it if it’s a text file.

Note: in addition to the arrow keys, it’s possible to open folders and files by clicking with the mouse.

To close the Ranger file manager, press Q.

Leave a comment