https://www.digitalocean.com/community/tutorials/installing-and-using-ranger-a-terminal-file-manager-on-a-ubuntu-vps
Installing and Using Ranger, a Terminal File Manager, on a Ubuntu VPS
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
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
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 file manager](https://i-blog.csdnimg.cn/blog_migrate/947901c51ec4739e91f5c3b6a03ab24d.png)
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 ascii picture viewer](https://i-blog.csdnimg.cn/blog_migrate/10960f45d604da84b7b510a9a67a4706.png)
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
- <ctrl>-f = Page down
- <ctrl>-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
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
- <space> = 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> = Delete selected file
![Ranger file tagging and marking](https://i-blog.csdnimg.cn/blog_migrate/beee3a30ae4a3b7bf039be564a4c5c5e.png)
Tagged and selected files in ranger's current working directory.
Tabbed Browsing
Ranger also incorporates tabbed functionality to allow multiple viewports into the filesystem. Here are the most common tab control keys:
- <ctrl>-n = Create new tab
- <ctrl>-w = Close current tab
- <tab> = Next tab
- <shift><tab> = Previous tab
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
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.
![Ranger bulk renaming](https://i-blog.csdnimg.cn/blog_migrate/1e05229e90d6fee67aaf731e885a88a3.png)
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.