Skip to main content
  1. Tutorials/

Installing and Using Ranger, a Terminal File Manager, on a Ubuntu VPS

Tutorials Applications Miscellaneous Ubuntu
Introduction>

Introduction #

Ranger is a terminal file manager with vim-like keybindings that uses the ncurses library to provide a powerful interface for your filesystem.
Ranger uses conventions common to both text-based file managers, such as Midnight Commander, and graphical file managers, such as Mac OS X’s Finder.

Installing Ranger>

Installing Ranger #

Ranger is in Ubuntu’s default repositories. It can be installed easily with apt-get.
We will also install some other applications that allow ranger to preview various file formats effectively.

sudo apt-get update
sudo apt-get install ranger caca-utils highlight atool w3m poppler-utils mediainfo

Start ranger for a moment and exit. This will allow ranger to create the directory structure for its configuration files:

ranger
Q

Now ranger has created its configuration directory and we can copy its configuration files with the following command:

ranger --copy-config=all
creating: /home/DemoUser/.config/ranger/apps.py
creating: /home/DemoUser/.config/ranger/commands.py
creating: /home/DemoUser/.config/ranger/rc.conf
creating: /home/DemoUser/.config/ranger/options.py
creating: /home/DemoUser/.config/ranger/scope.sh

If you would like to modify the configuration files later, you can locate them in ~/.config/ranger:

cd ~/.config/ranger
Using Ranger>

Using Ranger #

Before we begin exploring the features of ranger, it would be helpful to have some example files to look at. Let’s acquire some files:

cd ~
wget http://upload.wikimedia.org/wikipedia/commons/4/47/PNG_transparency_demonstration_1.png
wget http://upload.wikimedia.org/wikipedia/commons/4/40/Equipo1.gif
wget http://upload.wikimedia.org/wikipedia/commons/f/f8/Cula_Duca.jpg
cp /usr/share/doc/shared-mime-info/* .
tar -czvf zipped.tar.gz README copyright

Now start ranger:

ranger

You should see a three column layout. This type of file tree representation is known as “Miller columns”. It is a style that most people today would associate with Mac OS X’s “Finder” file manager.
The middle column is the current working directory. In this case, it should be showing your home directory.
The left pane is the current directory’s parent directory. The right pane shows a preview (if available) of the file you are currently interacting with in the middle column.

Ranger showing a gzipped text file in its preview pane.
If you move down the list of example files using the arrow keys, you will see how the preview pane changes depending on the file type you are viewing.
Text files are displayed in a simple pager, usually with the “less” program. Zipped files are automatically uncompressed and viewed in the same way. Even the example pdf file is converted to text for our viewing.
If you choose an image file, it is displayed using colored ascii art. The image clarity will depend a lot on your window size. If you expand the window, you should be able to see more detail.

Ranger showing an ascii representation of an image file in its preview pane.

Navigation #

Ranger uses many of the same keybindings as “vim”. For instance, the movement commands mirror vim closely:

j = Move down
k = Move up
h = Move to parent directory
gg = Go to the top of the list
G = Go to the bottom of the list
-f = Page down
-b = Page up
J = Page down 1/2 page
K = Page up 1/2 page
H = Go back through navigation history
L = Go forward through navigation history

There are also some directory-specific shortcuts to move to common directories:

gh = cd ~
ge = cd /etc
gu = cd /usr
gd = cd /dev
go = cd /opt
gv = cd /var
gm = cd /media
gM = cd /mnt
gs = cd /srv
gr = cd /
gR = cd to ranger’s global configuration directory

Working with Files>

Working with Files #

Ranger allows you to perform many different operations on files from within its interface. Here are some of the most common:

i = Display file (useful if you’d like to view a text file in a pager instead of editing it)
l or E = Open file (opens file in default file-handler)
r = Open file with… (allows you to choose program to use)
o = Change sort order (follow by character in menu selection)
z = Change settings (commonly used toggle settings)
zh = View hidden files
= Select current file
t = Tag file (you can perform actions on tagged files)
cw = Rename current file
/ = Search for files
n = Jump to next match
N = Jump to previous match
yy = Yank (copy) file
dd = Mark file for cut operation
= Delete selected file

Tagged and selected files in ranger’s current working directory.

Tabbed Browsing>

Tabbed Browsing #

Ranger also incorporates tabbed functionality to allow multiple viewports into the filesystem. Here are the most common tab control keys:

-n = Create new tab
-w = Close current tab
= Next tab/>
= Previous tab

General Commands>

General Commands #

These commands control ranger itself:

? = View ranger man page
1? = Keybindings help
2? = Command help
3? = Settings help
R = Reload current directory
Q = Quit

Command Interface>

Command Interface #

Like vim, ranger also includes a robust command interface. This allows you to manipulate files in more complex ways. The abilities are extensive, so we will only be covering a few:

! = Execute a command from the shell (non-ranger commands)
= Execute a ranger command
du = Measure disk usage of current directory
chmod = Change permissions of current file

There are a number of flags that you can pass to commands to modify the operation of the commands. They should be used with a dash “-” after typing “!” for shell commands or “:” for ranger commands:

-s = Discard the output of the current command.
-d = Detach the process and run in the background
-p = Return the output in ranger’s file pager
-w = Do not return immediately after command execution. Hang until “Enter” is pressed
-c = Perform command on current file, not the selected files

Ranger also allows you to target specific files by substituting groups of files for command operations. It accomplishes that by using placeholders that will be expanded with the correct files upon execution:

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

For example, if we wanted to change the names of multiple files, we could select them all with the space bar. After that, we can type:

:bulkrename %s

This is a great way to rename multiple files. It gives you every file you’d like to change in a text editor. You simply modify as necessary and then exit out. The file manager will perform your changes when after you confirm.

Renaming with ranger’s bulkrename command.
Ranger allows us to mark different groups of files at the same time. This gives us great flexibility if we want to perform multiple operations based on different criteria.
By Justin Ellingwood