How to use Ranger for navigating files from the command line | Opensource.com

How to use Ranger for navigating files from the command line

Browse and preview files from the terminal with Ranger.

computer screen
Image by : 
Opensource.com
x

Subscribe now

Get the highlights in your inbox every week.

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:

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

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.

collection of hardware on blue backround

Time-saving shortcuts for a commonly used open source tool.
rainbow colors on pinwheels in the sun

By making pre-compiled Python packages for Raspberry Pi available, the piwheels project saves users significant time and effort.

About the author

Ben Nuttall - 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.