A modern file manager for the command line
Command Line – ranger

© Photo by Brian Mann on Unsplash
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
Direct Download
Read full article as PDF:
Price $2.95
Subscribe to our Linux Newsletters
Find Linux and Open Source Jobs
Subscribe to our ADMIN Newsletters
News
-
An All-Snap Version of Ubuntu is In The Works
Along with the standard deb version of the open-source operating system, Canonical will release an-all snap version.
-
Mageia 9 Beta 2 Ready for Testing
The latest beta of the popular Mageia distribution now includes the latest kernel and plenty of updated applications.
-
KDE Plasma 6 Looks to Bring Basic HDR Support
The KWin piece of KDE Plasma now has HDR support and color management geared for the 6.0 release.
-
Bodhi Linux 7.0 Beta Ready for Testing
The latest iteration of the Bohdi Linux distribution is now available for those who want to experience what's in store and for testing purposes.
-
Changes Coming to Ubuntu PPA Usage
The way you manage Personal Package Archives will be changing with the release of Ubuntu 23.10.
-
AlmaLinux 9.2 Now Available for Download
AlmaLinux has been released and provides a free alternative to upstream Red Hat Enterprise Linux.
-
An Immutable Version of Fedora Is Under Consideration
For anyone who's a fan of using immutable versions of Linux, the Fedora team is currently considering adding a new spin called Fedora Onyx.
-
New Release of Br OS Includes ChatGPT Integration
Br OS 23.04 is now available and is geared specifically toward web content creation.
-
Command-Line Only Peropesis 2.1 Available Now
The latest iteration of Peropesis has been released with plenty of updates and introduces new software development tools.
-
TUXEDO Computers Announces InfinityBook Pro 14
With the new generation of their popular InfinityBook Pro 14, TUXEDO upgrades its ultra-mobile, powerful business laptop with some impressive specs.