A modern file manager for the command line
Command Line – ranger
Ranger offers a wealth of commands – many with alternatives – and less reliance on a mouse.
Linux has all the necessary commands for manipulating files, everything from ls
and cp
to rm
and mv
. However, file managers have the advantage of centralizing all the commands and requiring less knowledge in all except the most advanced circumstances. In fact, file managers remain so useful that Midnight Commander (mc
) continues to be used at the command line 27 years after it was first released. A more recent command-line file manager is ranger [1], which uses many Vim keybindings and is written in Python, which allows for the easy creation of custom scripts.
Ranger is available in many distributions, and the latest version can be downloaded from GitHub [1]. It requires Python 3 and includes a long list of suggested packages for full functionality, such as w3m for graphics display, poppler-utils for PDF display, and python-pygments for code highlighting. It creates the directory ~/.config/ranger/rc.conf
with the configuration files in Table 1 (shown in Figure 1).
Table 1
Ranger Configuration Files
rifle.conf |
Configuration for |
commands.py |
Defines the default ranger console commands |
commands_full.py |
Reference file for custom commands |
rc.conf |
The main configuration file |
scope.sh |
Defines how to handle preview files |
The configuration files also function as documentation on how to customize; although, unless you have a knowledge of Python, these files may be of limited use. A few notes are given in the GitHub repository [2].
Upon startup, ranger first references the global configuration in /etc/ranger/rc.conf
by default and then ~/.config/ranger/rc.conf
. To avoid potential conflicts, you should add to the top of rc.conf
the line RANGER_LOAD_DEFAULT_RC =FALSE
so that ranger bypasses the global configuration, and make all your edits in ~/.config/ranger
(Figure 2). While making this change, you might also scan the local rc.conf
for other customizations, such as whether ranger displays hidden files or if deletions require confirmation. The other files can be ignored unless you want to customize.
Basic Navigation
If ranger is started as a bare command, it displays your home directory. However, you can also follow the command with a space-separated list of directories and files. A few options are available, but most are unnecessary, especially if you add a list of directories. For many, the only useful option may be --show-only-dirs
. Each directory or file specified is opened in a tab in the order in which it is listed in the command. The number of directories or files open is listed in the upper right corner. To switch to another tab, press Tab or gt to move to the next tab, or Shift+Tab or gT to move to the previous tab. The keybinding gc will close the current tab, and Ctrl+N or gn opens a new tab. In addition, you may want to enter the command:
<C>:set show hidden true<C>
or add it to ~/.config/ranger/rc.conf
to show hidden files as the permanent default.
Each tab has three panes (Figure 3). The left-hand pane shows the top level directories, and the middle one the second level subdirectories. The right-hand pane shows the third-level subdirectories and files, with statistics at the bottom. Types of files are color-coded – for instance, PDF files are white, JPEGs orange, and FLAC files pink. Basic navigation is with arrow keys, with more complex commands assigned to other keys and key combinations (see Table 2). Default key assignments are based on Vim or mc
, making ranger easy for experienced command line users to learn. An online summary of basic navigation displays when you press the g key.
Table 2
Basic ranger Navigation
Up arrow, Page Up |
Up a page |
Ctrl+U |
Up half page |
Down arrow |
Go down |
Ctrl+F, Page Down |
Down a page |
Ctrl+D |
Go down half page |
Left arrow |
Go left |
Right arrow |
Go right |
Home |
Move to top |
End |
Move to bottom |
cd |
Change the working directory to a specific directory |
gh |
Change the working directory to your home |
gm |
Change the working directory to /media |
gM |
Change the working directory to /mnt |
gu |
Change the working directory to /usr |
H |
Back in history |
L |
Forward in history |
q |
Quit |
Copying, Moving, and Deleting
To access basic file management, press y for a list of copy and paste commands and d for move or delete commands (Figure 4). Note that, like Vim, ranger uses the term "yank" instead of paste. Besides the basic commands, the lists also contain advanced options for the basic keystrokes (Table 3). Alternatively, you can press r with a file selected or the s key and use the standard shell commands instead.
Table 3
Basic File Manipulation
yy |
Copy |
yp |
Paste (yank) |
yd |
Paste directory (yank) |
dd |
Cut |
dD |
Delete (yank) |
ya, da |
Add selection to a list of files |
yr, dr |
Remove selection from a list of files |
yt, dt |
Toggle list of files on or off |
For actions involving more than one file, you can use copy or cut modes. Pressing a adds a selected file to the multiple files, while r removes the selected file. When you are finished creating a list of files, you can proceed with the operation by pressing t to toggle to the copy or cut mode.
To rename or move a selection, press wa. For renaming multiple files or directories, you can also use the :bulkrename
command.
Viewing and Searching
Although ranger is a command-line application, it can open other applications to view formats that include PDF, OpenDocument (LibreOffice), BitTorrent, HTML, and SVG. The supported formats and how they are handled are listed in the scope.sh
configuration file. You can use the examples in scope.sh
to add support for other formats. If a file is properly configured in scope.sh
, all you need to do is select the file and press the Enter key. Some files display in the right-hand pane (Figure 5), and others open in an application in a new window. If a file opens in the righthand pane, but you would like to view it in its native application, you can use the :travel
command. Should a file type not be supported, you can open a command line and run the rifle
command, which supports a wide variety of formats.
At times, you may just want to view file attributes with :linemode
. The command can be completed by filename
, permissions
, fileinfo
, mtime
(last time modified), or sizemtime
(the size and time of the last modification). You can modify these completions by using them with :meta
.
The :travel
command can also be used to quickly find directories. Just enter the name of the directory at the end of the command. Another alternative is to create a bookmark for a selected directory by pressing m and assigning a letter or number. A list of existing bookmarks displays as a crib, and you can create the bookmark by pressing m a second time. To jump to a bookmark, press ` followed by the bookmark's letter or number.
Within directories, you can use / or f to find a file. If the file is not found, you can search for it in the next file by pressing n, or in the previous directory by pressing N. Visual searches can be enhanced with :filter REGEX
to reduce the number of files displayed. You can also sort by file size with os or arrange sub-directories by size with du.
Buy this article as PDF
(incl. VAT)
Buy Linux Magazine
Subscribe to our Linux Newsletters
Find Linux and Open Source Jobs
Subscribe to our ADMIN Newsletters
Support Our Work
Linux Magazine content is made possible with support from readers like you. Please consider contributing when you’ve found an article to be beneficial.
News
-
Linux Kernel 6.13 Offers Improvements for AMD/Apple Users
The latest Linux kernel is now available, and it includes plenty of improvements, especially for those who use AMD or Apple-based systems.
-
Gnome 48 Debuts New Audio Player
To date, the audio player found within the Gnome desktop has been meh at best, but with the upcoming release that all changes.
-
Plasma 6.3 Ready for Public Beta Testing
Plasma 6.3 will ship with KDE Gear 24.12.1 and KDE Frameworks 6.10, along with some new and exciting features.
-
Budgie 10.10 Scheduled for Q1 2025 with a Surprising Desktop Update
If Budgie is your desktop environment of choice, 2025 is going to be a great year for you.
-
Firefox 134 Offers Improvements for Linux Version
Fans of Linux and Firefox rejoice, as there's a new version available that includes some handy updates.
-
Serpent OS Arrives with a New Alpha Release
After months of silence, Ikey Doherty has released a new alpha for his Serpent OS.
-
HashiCorp Cofounder Unveils Ghostty, a Linux Terminal App
Ghostty is a new Linux terminal app that's fast, feature-rich, and offers a platform-native GUI while remaining cross-platform.
-
Fedora Asahi Remix 41 Available for Apple Silicon
If you have an Apple Silicon Mac and you're hoping to install Fedora, you're in luck because the latest release supports the M1 and M2 chips.
-
Systemd Fixes Bug While Facing New Challenger in GNU Shepherd
The systemd developers have fixed a really nasty bug amid the release of the new GNU Shepherd init system.
-
AlmaLinux 10.0 Beta Released
The AlmaLinux OS Foundation has announced the availability of AlmaLinux 10.0 Beta ("Purple Lion") for all supported devices with significant changes.