Ranger on Linux – A Complete Terminal File Manager For Linux

In this article, we’re going to learn about an exciting new file manager called Ranger. For many of us, who switch to Linux from Windows, using the terminal might feel daunting at first.

But the more you use it, the more you realize that not only it’s not as intimidating as you initially thought, but it is also faster than its graphical counterparts. However, some things don’t translate well to the terminal and one of those is the concept of a file manager.

Recent article: How to change DNS on Linux [Step by Step Guide]

What is Ranger on Linux?

While you can navigate files and folders using the cd and ls commands, it doesn’t have the same feel and speed as a full-fledged file manager does.

With ranger, you can seamlessly browse and manage your files from the terminal itself. You can display and open files with one click, just like you would in any file manager and it also supports vim keybindings for lightning-fast navigation.

Features

  • Minimal UI
  • VI keybindings for faster navigation
  • Integrated with rifle, that automatically recognizes which program to use for what file type.
  • Extensible and customizable

How to Install Ranger

Ranger ships for almost all Linux distributions. Apart from the system package manager, you can also install it through PyPi

  • Debian / Ubuntu
sudo apt install ranger
sudo dnf install ranger
  • Arch
sudo pacman -Sy ranger
  • Gentoo
sudo emerge -U app-misc/ranger
  • Void Linux
sudo xbps-install ranger
  • PyPi
pip install ranger-fm

For any other distro, check out Repology.

How To Use Ranger?

You can start ranger by just executing ranger in terminal.

Ranger File Manager 1

This is the default view of Ranger. To go to subdirectories you can navigate right and to go to previous directories you can go left and the metadata of the selected files and folders is displayed at the bottom.

Generating configs

You can generate the local configs for ranger by executing the following command.

ranger --copy-config=all

This generates four major config files in ~/.config/ranger/

  • commands.py : Defines ranger console command
  • rifle.py : Defines how and which programs to use to launch files
  • rc.conf : Ranger keybindings and settings
  • scope.sh : Defines how to handle file previews

Basic Keybindings

Ranger uses basic VIM keybindings for navigation. However, if that is not what you prefer you can change it in rc.conf which will likely be located in your ~/.config/ranger directory

  • 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: Changing settings
  • dD: Delete file

Previewing Files using Ranger

You can preview various file types in ranger without opening them. Any kind of text files and documents (.txt, .py, .odt, .docx, .epub, .pdf) can be previewed by default at text. Ranger can also preview torrents and video thumbnails. All the configuration regarding previewing files is handled in scope.sh.

Preview Of Text File Ranger
Preview Of Text File

Image previews

Image previews are available on terminals like urxvt, iTerm2, Kitty and Terminology. To enable Image previews, go to rc.conf after generating configs and set preview_images_method to true.

Ranger Image Preview 1

PDF preview on Ranger File Manager

By default, PDF converts to text and is previewed by ranger like shown below.

To get an image thumbnail as a preview instead of text, go-to scope. sh and uncomment the following lines from the code. By “uncommenting”, I mean remove the “#” symbol before them.

Ranger Pdf Prewvie Code 1

Now your previews should look something like this.

Ranger Pdf Preview

Console Commands

Just like VIM, Ranger has options for console commands. You can use them by typing “:” followed by the command. Some useful commands are listed below.

  • :bulkrename – Rename in bulk
  • :openwith – To open a select file with a program of your choice
  • :touch FILENAME – Create a file
  • :mkdir FILENAME – Create a directory
  • :shell <command> – To run a command in shell (bash/zsh etc)
  • :delete – Delete files

These commands are usually with placeholders and flags. The important ones are

Placeholders:

  • %f – Substitute highlighted file
  • %d – Substitute current directory
  • %s – Substitute currently selected files
  • %t – Substitute currently tagged files

Example – :delete %s deletes all current select files.

Flags:

  • w – To see output of external command, like this :shell -w free
  • tTo fork console program (run in a new terminal window), like this :shell -t nano
  • f – To fork GUI program, , like this :shell -f firefox
  • r – To run program with root rights.

Conclusion

We covered how to install, set up, and use ranger, a terminal file manager. It works just like a normal file manager but since it’s in the terminal and supports various scripts, key-binds, and commands, it is more efficient than using a graphical user interface to browse files. It also looks quite cool in my opinion. To learn more about ranger, check references. Thank you and keep exploring!

References

What is Ranger?

Ranger is a minimal file manager that runs in the command line and is commonly used in Linux systems. It allows users to navigate folders, preview files, and execute commands right from the terminal.

How can I use Ranger to preview files?

To preview a file using Ranger, navigate to the file in the Ranger interface and press the designated preview key. This will display the content of the file within the Ranger window.

Can I customize keybindings in Ranger?

Yes, Ranger is highly customizable in terms of keybindings. You can define your preferred key combinations to perform various actions within the program.

Is Ranger considered the best file manager for Linux?

Ranger is a powerful and programmatic file manager for Linux users. While some users prefer graphical file managers, many find the customizable and console-based nature of Ranger to be the best option for their workflow.

How do I navigate quickly in Ranger?

In Ranger, you can use various shortcut that saves times and keystrokes to navigate through folders and files quickly. Understanding the keybindings and customizing them to your liking can greatly improve your navigation experience.

Can I open multiple tabs in Ranger?

Yes, you can open multiple tabs simultaneously in Ranger. This feature allows you to work on multiple locations