Navigating the filesystem through the terminal is a regular thing that many Linux users perform on a daily basis. Most of the time, they rely on commands such as cd, ls, cp, and mv to move through different directories, copy files, delete files, and many more.
However, what if you could accomplish these operations with just one convenient command? Let me introduce you to the Ranger File Manager.
In this article, you will learn how to install Ranger file manager on Ubuntu 22.04 as well as how to configure and use it effectively.
What is Ranger File Manager
Ranger File Manager is a command-line-based file manager that is able to perform many operations such as navigating between directories, copying files, deleting files, and many more.
The interface of Ranger is separated into three columns. The first column is to display the directory tree, allowing you to see the parent directories and their relative directories. The second column is to display the current active directory, this will display any files or directories that are available in the currently active directory. And the third column is to display the preview content of the selected file or directory in the second column.
With this kind of interface, Ranger is so much fun to work with, especially when you are also a Vim user. Because the Ranger File Manager uses keybindings that are pretty similar to Vim. This of course will make your navigation more seamless.
Ranger Features
- Intuitive Interface. Ranger provides a three columns interface that makes it easier to navigate and preview the files and directories.
- Vim-like Keybindings. Easily use Ranger if you are already familiar with Vim.
- Preview Functionality. Easily preview the content of files or directories by taking advantage of the third column for previewing contents.
- Customizability. You can customize many things in Ranger, such as colors, keybindings, preview settings, and many more.
- File Tagging and Marking. Ranger allows you to assign custom tags or labels to files or directories to help you organize your files.
How to Install Ranger on Ubuntu 22.04
Ranger is available on most Linux distros, but for this article, we will just focus on installing Ranger on Ubuntu 22.04.
To install Ranger on Ubuntu 22.04, first, you will need to update the package repositories with the latest software updates.
sudo apt update
Once the package repositories are updated, we can proceed to the installation process by running the following command:
sudo apt install ranger
Wait until the installation process to complete.
Starting the Ranger File Manager
Now the Ranger file manager is successfully installed on your Ubuntu machine, you can launch it by simply typing ranger in the terminal
ranger
the ranger file manager will launch with the default three columns interface.
you can run Ranger from a specific directory by adding the directory path after the Ranger command.
ranger ~/Documents
This will open Ranger directly to the ~/Documents
directory.
Ranger Configuration
From a fresh installation, you can immediately use the Ranger file manager to navigate through your file systems. However, there are options available to configure Ranger in order to personalize your preferences. You can customize various options such as changing the color schemes, setting the keybindings, and more.
Copying the Ranger Config Files
Before you can configure the Ranger file manager, you will need to copy all the default config files to the ~/.config/ranger/
directory. To do this, simply run the command below:
ranger --copy-config=all
by running this command, it will copy some configuration files, including riffle.conf
, commands.py
, commands_full.py
, rc.conf
, and scope.sh
.
However, in this tutorial, we will only need to edit the rc.conf
file, because most of the configuration can be set by editing it.
Modifying the Keybindings
Ranger provides a lot of keybindings you can use, these keybindings have the default behavior that is declared on the rc.conf
file.
the syntax for keybindings in Ranger is written in the following format:
map key action
map to define the keybinding, key is the keyboard combination you want to set, while action is a specific action that will be executed when the key combination is pressed.
For example:
map gr cd /
This declaration will set the gr shortcut to do the action cd /
which is to change the directory to the root directory(/).
You can either modify the existing keybindings or create a new one for the same action. Yes, you can have multiple keybindings for the same action.
To create a new keybinding, open the rc.conf
file using a text editor:
nano ~/.config/ranger/rc.conf
Go to the end of the file, and you can add the new keybindings there.
For instance, you can assign gD
to set the action to go to the ~/Downloads
directory
map gD cd ~/Downloads
Once you’ve done adding the keybindings, save the file and restart the Ranger file manager to see the effect.
Now when you press gD
, Ranger will change the directory to ~/Downloads
.
Showing the Hidden Files
By default any files or directories that have names starting with dot (.) are hidden. If you want to see the hidden files in Ranger you have a couple of options:
Using keybindings. You can use keybindings to toggle the display of hidden files in Ranger. The keybinding to show/hide the hidden files is zh
. Pressing zh
one time will show the hidden files, and pressing zh
once again will hide the hidden files.
By editing the rc.conf file. This method will allow you to always show the hidden files, even if you restart the Ranger file manager. To do so, you need to edit the rc.conf
file:
nano ~/.config/ranger/rc.conf
Then, look for a line starting with set show_hidden
, if it’s written as set show_hidden false
, you can change it to set show_hidden true
to make the hidden files visible. Or if the rc.conf
file is still empty you can add it to the configuration.
set show_hidden true
Once you have done that, save the file, and restart the Ranger file manager. Now, the hidden files should always be visible when you are using Ranger.
Changing the Color Schemes
Ranger does provide the ability to change the color scheme for its appearance. This will make the Ranger appearance better and more comfortable to work with.
Basically, to change the ranger color scheme, you just need to edit the rc.conf
file, and search for a line starting with set colorscheme
.
Ranger comes with some predefined color schemes that you can use such as default, snow, jungle, and solarized.
For example, if you want to set the color scheme to jungle, you can set the configuration as follow:
set colorscheme jungle
Save the file and try to relaunch Ranger to see the changes. If the configuration is set properly, the color scheme should be applied already.
Movement and Keybindings
In order to use the Ranger file manager efficiently, you should know the basic movements and keybindings to do many operations such as navigation through directories, opening files, deleting files, copying files, and many more.
These operations are basic and you definitely need to know so you can comfortably use the ranger file manager.
Navigating Through Directories
Navigation in Ranger is pretty similar to what Vim has. It uses hjkl keys to move left, bottom, up, and right. To get the idea more clearly, you can look at the table below:
Key | Function |
---|---|
h | move to the parent directory |
j | move the cursor down |
k | move the cursor up |
l | move to the selected directory |
You can also move the cursor faster by using the keybindings J to move the cursor down faster, and K to move the cursor up faster.
And then you can press gg to go to the top of the files, and press G to go to the very bottom of the files.
Key | Function |
---|---|
J | move the cursor down faster |
K | move the cursor up faster |
gg | move to the very top of the files |
G | move to the very bottom of the files |
Opening files
When the ranger cursor hovers over a file, you can open that particular file by pressing the enter
key or l
key. Doing so will open the file based on the file format.
For example, if you open a text file, it will be opened in the Vim text editor or the default editor that is defined in the $EDITOR variable.
The programs for opening each specific file format have been defined in the rifle.conf
file. If you want to modify which program opens a specific format, you can configure it in that file.
Copying files
To copy files in Ranger is pretty simple, you just need to select the file you want to copy, and press yy to copy the file into the buffer. Then navigate to the directory where you want to paste the file. Once you are in the desired directory, press pp to paste the file.
Deleting And Moving Files
Sometimes you need to delete files. With Ranger, you can easily delete files by following these steps:
- Highlight the file you want to delete in Ranger.
- Press the
dD
keys, and then hit Enter to confirm the deletion.
Moving or cutting files is another option. Instead of deleting the file, you can move it to another directory using the following steps:
- Highlight the file you want to move.
- Press
dd
to start the move operation. - Navigate to the desired destination directory.
- Once you are in the desired directory, press
p
to paste the file. The file will be moved from its original location to the current directory.
Renaming files
Ranger also provides the ability to rename files, which is an important operation that you often need to do.
To rename a file in Ranger is quite simple:
First, highlight the file you want to rename.
And then press cw
keys, and immediately the rename command will appear at the bottom section.
write the new name you want to change into, and hit enter to apply the changes.
The file name should now be successfully changed to the new name.
Creating Directories
To create a new directory in Ranger, you can simply type :mkdir
command, followed by the name of the folder you want to create.
For example, I want to create a new directory called books. so I will type :mkdir books
and hit enter.
Marking Files
Marking is a very important feature in Ranger that allows you to mark multiple files and directories in order to do bulk operations such as deleting or copying multiple files.
To mark files in Ranger, select the file you want to mark and press the space key. Marked files will be colored differently. You can mark as many files as you need.
Once you have finished marking the files, you can perform bulk operations on the selected files. For example, to delete them, simply press dD
and hit Enter. Confirm the deletion by pressing Y
.
Quitting From Ranger
When you no longer need to use Ranger and want to quit the program, you have a couple of options. You can simply press Q
to exit Ranger, or you can type :q
and hit Enter, which also works too.
Conclusion
By reaching this end section, you should have learned about how to install Ranger file manager on the Ubuntu machine. Although this is definitely a long tutorial, hopefully, it will be helpful for you so you can use the Ranger file manager more confidently.
If you have any questions or difficulty when installing Ranger, don’t hesitate to ask me a question in the comment section below.