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.
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:
Now ranger has created its configuration directory and we can copy its configuration files with the following command:
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:
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:
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.
Ranger uses many of the same keybindings as "vim". For instance, the movement commands mirror vim closely:
There are also some directory-specific shortcuts to move to common directories:
Ranger allows you to perform many different operations on files from within its interface. Here are some of the most common:
Tagged and selected files in ranger's current working directory.
Ranger also incorporates tabbed functionality to allow multiple viewports into the filesystem. Here are the most common tab control keys:
These commands control ranger itself:
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:
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:
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:
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:
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.
Thanks for learning with the DigitalOcean Community. Check out our offerings for compute, storage, networking, and managed databases.