Manage your files in your Linux terminal with ranger

Try this lightweight open source tool to preview files without leaving the terminal.
3 readers like this.
Filing cabinet for organization

The most basic way to look at your files and folders is to use the commands ls and ll. But sometimes, I want to see not just the file metadata but also the contents of a file at a glance. For that, I use ranger.

If you love working out of your console and using Vim or Vi, and you don’t want to leave your terminal for any reason, ranger is your new best friend. Ranger is a minimal file manager that allows you not only to navigate through the files but also to preview them. Ranger comes bundled with rifle, a file executor that can efficiently choose programs that work with a given file type.

Installing ranger on Linux

Ranger can be installed in Fedora or any RPM-based distro by running

$ sudo dnf install ranger

Ranger is also available for other distros and macOS.

Using ranger for the first time

As a user, you can start ranger by simply typing $ ranger on your favorite terminal. The arrow keys give way to the navigation. This screenshot is an excellent example of how I can preview the code of the config.example file stored in Kernel-tests.

Screenshot of terminal showing config.example highlighted and a preview of the file in the terminal to the right

(Sumantro Mukherjee, CC BY-SA 4.0)

Picking any file and hitting F4 opens up your default editor and lets you edit the files right away!

What about images and videos?

Using rifle with ranger lets you quickly find the program associated with a given file. Hovering over an image and then trying to open it is very simple; just hit Enter. Here’s how that looks:

Screenshot of a PNG file preview over a terminal window

(Sumantro Mukherjee, CC BY-SA 4.0)

Hitting i on an image file will give the user all the EXIF data. Hitting Shift+Enter will open the PDF file.

A screenshot showing a preview of a PDF file (tickets to a museum) floating over the terminal window

(Sumantro Mukherjee, CC BY-SA 4.0)

The same key combo will open and start playing videos in the system's default video player that supports the codec. The example below is an mp4 video, which plays just fine on VLC.

Screenshot of a Bugcrowd University Cross Site Scripting video in VLC media player, previewed over the terminal

(Sumantro Mukherjee, CC BY-SA 4.0)

File ops

The following key bindings work well unless otherwise configured by the Vim user.

j: Move down
k: Move up
h: Move to parent directory
gg: Go to the top of the list
i: Preview file
r: Open file
zh: View hidden files
cw: Rename current file
yy: Yank (copy) file
dd: Cut file
pp: Paste file
u: Undo
z: Change settings
dD: Delete file

Console commands

Sometimes I have a folder that contains screenshots of a particular software when I am drafting articles. Selecting or marking files by hitting Space and then typing :bulkrename helps me move all the weird timestamps to, for example, lorax1, lorax2 , and so on. An example is below:

Screenshot of terminal showing timestamped files that can be renamed with the bulkrename command

(Sumantro Mukherjee, CC BY-SA 4.0)

Other useful console commands include:

:openwith: Open a select file with a program of your choice
:touch FILENAME: Create a file
:mkdir FILENAME: Create a directory
:shell <command>: Run a command in shell
:delete: Delete files

Will it work in tty2/3/4?

As someone who works in quality assurance (QA), I've found that searching for logs and reading them has never been easier. Even when my Gnome Display Manager crashes, I can switch over to my tty2, log in with my username and password, and start ranger with superuser permission, and then I am all sorted to explore!

Ranger is a great tool for working with files without ever having to leave the terminal. Ranger is minimal and customizable, so give it go!

What to read next
Tags
User profile image.
Hey, open source folks! I am Sumantro, hailing from India (the eastern part - former capital during the British era AKA Kolkata). I love sharing knowledge and writing about technology and experiences (mostly that I try every day).

1 Comment

Thanks for sharing this. I'm a long-time fan of ranger. Others may well propose alternative cli-based ui options for listing files, such as perhaps even within other tools or editors. For folks who don't use those other tools already though, ranger fits the bill for easily viewing files and folders.

If you're open to feedback, it would help to list the arrow keys in addition to the letter keys for moving up/down, etc. I know you mention the arrows in passing earlier in the article. But folks scanning the article and seeing that "file ops" list could be misled to think only letter keys are supported, which could put some off.

The ease of using arrow keys is what makes ranger so helpful/natural for folks dealing with Linux only occasionally--or newly and until they learn such traditional letter keys, for use in other tools.

Creative Commons LicenseThis work is licensed under a Creative Commons Attribution-Share Alike 4.0 International License.