How to use Ranger for navigating files from the command line

Browse and preview files from the terminal with Ranger.
103 readers like this.
computer screen

Opensource.com

Ranger is an incredibly handy terminal-based file navigator that's written in Python and is available for Linux and Mac.

Ranger allows you to navigate your filesystem using the arrow keys on your keyboard: Up/Down to select files in the current directory (middle pane), and Left/Right to hop back and forth through levels and into directories. When you're focused on a directory, it shows you the contents in the right-hand pane:

Navigating directories in Ranger

When you're focused on any kind of text file, it shows you a preview of the contents in the pane:

Previewing text file in Ranger

If you hit the Right arrow key, the file opens in your default editor (e.g., Nano or Vim), and quitting the editor brings you back to where you were. You can even use some Vim-like key commands to manage your files, like D to delete a file. I'm still learning all the handy tricks, but just being able to navigate the filesystem using arrow keys, easily see the contents of multiple directories, and update the view dynamically is really handy. The ability to quickly view or edit a file while you skim through some content is great, too.

I'd highly recommend Ranger to anyone who regularly uses the command line on a Raspberry Pi, Linux PC or server, or a Mac. Whether you're confined to SSH, prefer command-line access, or need to navigate around quicker than with the GUI, it's a great tool. No more cd, ls, cd, ls, cd .. tree, find, grep, etc.

Install Ranger

To install it on Debian/Ubuntu systems:

sudo apt install ranger

Or on Mac:

brew install ranger

Then type ranger to begin.

The version in the current Ubuntu LTS (18.04) and current stable Debian/Raspbian (Stretch) is unfortunately dependent on Python 2.7, but it's been upgraded to Python 3, and that version can be found in Ubuntu (since 19.04 (Disco)) and Debian Buster. It's also on PyPI, so you can pip install ranger-fm (not ranger!) to install it.


This was originally published on Ben Nuttall's Tooling blog and is reused with permission.

What to read next
User profile image.
Ben is a software engineer for BBC News Labs, and formerly Raspberry Pi's Community Manager. He's into Linux, Python and all things open source! Follow Ben on Twitter @ben_nuttall.

2 Comments

I use ranger on Android within a termux shell. Combined with micro editor I've been able to get a fair bit done. I also set ranger to 2 columns instead of 3, in Rangers conf file. Also, you'll want to change your EDITOR AND VISUAL environment cars. I also alias e as exit, so it's S for shell then e to return.

How have I been living without this app ?!!
Thanks Ben

Creative Commons LicenseThis work is licensed under a Creative Commons Attribution-Share Alike 4.0 International License.