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, there are some things that 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?
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.
- 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
sudo pacman -Sy ranger
sudo emerge -U app-misc/ranger
- Void Linux
sudo xbps-install ranger
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.
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.
You can generate the local configs for ranger by executing the following command.
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
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.
Image previews are available on terminals like
Terminology. To enable Image previews, go to rc.conf after generating configs and set
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.
Now your previews should look something like this.
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
- %f – Substitute highlighted file
- %d – Substitute current directory
- %s – Substitute currently selected files
- %t – Substitute currently tagged files
:delete %s deletes all current select files.
w– To see output of external command, like this
:shell -w free
t– To 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.
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!