Americas

  • United States
sandra_henrystocker
Unix Dweeb

The Linux ranger: What is it and how do you use it?

How-To
Feb 07, 20184 mins
LinuxUbuntu

The Linux ranger is a file manager that works in a terminal window and provides a smooth way to view and edit files.

For those of us who cut our technical teeth on the Unix/Linux command line, the relatively new ranger makes examining files a very different experience. A file manager that works inside a terminal window, ranger provides useful information and makes it very easy to move into directories, view file content or jump into an editor to make changes.

Unlike most file managers that work on the desktop but leave you to the whims of ls, cat and more to get a solid handle on files and contents, ranger provides a very nice mix of file listing and contents displays with an easy way to start editing. In fact, among some Linux users, ranger has become very popular.

As you start ranger, you will see a display that looks something like this:

shs@stinkbug /home/shs/bin
shs       bin               5   case1
          Desktop           0   killit
          Documents        11   prime
          Music             0   sieve
          Pictures          0   tryme
          Public            0
          Reports           8
          Templates         0
          Videos            0
          examples.desktop  8.77 K
          servers

drwxrwxr-x 2 shs shs 5 2018-0206 17:28   14.2K sum, 63G free  1/11 All

The first line shows the user and system, plus the directory that has its contents listed on the right.

The columns in the display show the current directory (shs), the subdirectories and files (bin, Desktop, etc.), the number of files within each directory or the file size (if it’s a file), the contents of the currently selected directory or the content of the currently selected file.

shs@stinkbug /home/shs/bin
shs     / bin                 5   case1    
       /  Desktop             0   killit    
      /   Documents          11   prime    files in bin
     /    Music               0   sieve     /
   dirs   Pictures            0   tryme    /
         Public              0
         Reports             8
         Templates           0
         Videos              0
          examples.desktop 8.77 K
          servers          61 B

drwxrwxr-x 2 shs shs 5 2018-0206 17:28   14.2K sum, 63G free  1/11 All

How to move around ranger

Moving around in ranger is easy and quickly becomes second nature.

  • q quit
  • => (right arrow) moves down a directory
  • <= (left arrow) moves up a directory
  • return — if current selection is a directory, opens the directory
  • return — if current selection is a file, opens the file for editing

The line at the bottom of the display is essentially the long listing of the file or directory, displaying the permissions, owner and group, date and time, size, etc. — typical long listing details. Ranger will use your EDITOR setting to determine what editor to use when you go to edit a file.

The editor that is invoked depends on your account settings. Change your settings with a command like this, and it will use vi.

VISUAL=vi; export VISUAL EDITOR=vi; export EDITOR

Ranger works with a series of optional config files. To load them, you would start ranger as shown below. It will set up your configuration files in a ~/.config/ranger directory.

$ ranger --copy-config=all
creating: /home/shs/.config/ranger/rifle.conf
creating: /home/shs/.config/ranger/commands.py
creating: /home/shs/.config/ranger/commands_full.py
creating: /home/shs/.config/ranger/rc.conf
creating: /home/shs/.config/ranger/scope.sh

Ranger is written in python and is an extremely clever tool for quick file browsing with little effort. It’s an easy-to-use file manager for both command line newbies and experienced Unix pros. It was developed by Roman Zimbelmann and is licensed under the terms of the GNU General Public License.

sandra_henrystocker
Unix Dweeb

Sandra Henry-Stocker has been administering Unix systems for more than 30 years. She describes herself as "USL" (Unix as a second language) but remembers enough English to write books and buy groceries. She lives in the mountains in Virginia where, when not working with or writing about Unix, she's chasing the bears away from her bird feeders.

The opinions expressed in this blog are those of Sandra Henry-Stocker and do not necessarily represent those of IDG Communications, Inc., its parent, subsidiary or affiliated companies.

More from this author