Configure >

I was looking for a tidy way to navigate directories in a bash shell, so that I could speed up my work a bit. I'm familiar with `cd` command and Tab key completion of names, but sometimes my mind goes blank, so having a visible list of directories to choose from would be way better for me. Actually, listing the current directory contents with `ls` and using the cursor keys and Enter to navigate would have simplified things for me, if that had been possible. But then my search brought me across Roman Zimbelmann's impressive python project, Ranger - the terminal based file browser.

ranger showing directories  ranger showing file content  ranger with image shown inline  ranger with image showing exif
Ranger, in fullscreen, showing directories the content of a text file shown in the pager an image file displayed inline EXIF data displayed for an image file
ranger with video info  ranger with audio file info  ranger with archive content  ranger with version control turned on for github repo
media info shown for a video file media info shown for an audio file content shown for an archive version control aware for github repo


download ranger (zip file) from Ranger git
unpack, and run `sudo make install'

or clone from git for latest version (need git installed)

If Ranger crashes with a python error about misuse of Tab indentation in multiple files, try downloading a previous release from Github (ranger/releases), just unzip enter the ranger dir and run ./ranger.py, and if it runs then install it with sudo make install

optional installs for Ranger:
w3m and w3m-image are responsible for in-line preview of images (only with rxvt, urxvt and xterm)

To release media drives that could be caught in a process such as w3mimgdisplay, then you will need to use Ctrl-C before ejecting.

After installing, copy the config files from /usr/local/lib so that you can make modifications

Note, the config files may be incompatible with new versions of ranger. Run 'man ranger' for details

Ranger is installed to /usr/local/lib/python2.7/dist-packages/ranger so on new installs you could copy, say, only the scope.sh and rc.conf files over, which are always being upgraded - backup your old ones first and then do a meld compare with the latest versions.

Check out the ranger Wiki to see how to update ranger.

What you can do is copy your original config files, install a newer ranger, run the above command and compare new and old contig files with meld

Arch Wiki page

To get started, three commands needed..

ranger launches ranger from the current dir in shell (I make a bash alias rr)
S in Ranger, drops to a shell at current dir (from where Ctrl-D or `exit' returns to Ranger)
q quits Ranger


And that's just the basics! There are endless possibilities with Ranger because it incorporates the bash shell.

Get my key mapping sheet!

Default key-bindings


arrowstraverse in/out of dir's, move up/down lists
j, {n} j move up 10 lines (default, I change it to 4), or move up 10 lines {n} times
k, {n} k move down 10 lines, or move down 10 lines {n} times
g {letter} quick go to (system level dir's) - gR go to ranger dir
g n new tab made at home
Ctrl-n new tab opened at current dir
tab, shift-tab switch tab
q quit tab or ranger if only one tab
u q restore closed tab
[ or {n}[ move up 1 dir in same parent, or move up n parent dir's
] or {n}] move down 1 dir in same parent, or move down n parent dir's
H move back 1 dir in history (I make this Alt-left)
L move forward 1 dir in history (I make this Alt-right)
m {x} bookmark the dir x (any letter/digit)
`{x} or '{x} go to dir bookmarked x
`` go to previous dir = effectively you can use `` to go back and forth between two locations
pg up, pg dn,
home, end
move down/up file list
d c update cumulative dir size
d u show dir content summary
J escape Ranger from reading a heavy dir/file


o t sort by type first
o s sort by size first
o a /o c /o m sort by time
o n sort natural
o {T/S/A/C/M} sort in reverse order
o r reverse the sort order

file actions

/, f enter file name to navigate (f can't do this with my keybinds as I make use of it)
n search newest file in dir, or next after search with /, f
N previous file after search
c.. set the next search order
o.. set the sort order
i focus a highlighted file with less (but only able to see part of file)
i to toggle focus, E to edit in nano
y y copy
y a copy add to buffer (can copy-paste files from multiple directories this way)
y r copy remove from buffer
y G copy all files from selected to bottom of list
y gg copy all files from selected to top of list
d d cut (da, dr also to cut from multiple directories, dG, dgg also)
p p paste
p P paste (add to queue)
p o paste with over-write
p O paste with over-write (add to queue)
u d clears copy/cut buffer, also uy (I change this to uu as it seems faster)
c w rename/bulk rename
I edit name, cursor at front (I change it to i, and make Alt-i view in pager)
A edit name, cursor at end
a edit name, cursor inside extension
E edit file with bash editor (I change this to fe - there is F4 as well - see how to set nano as editor below)
insert touch (create new file) (I add ft)
delete deletes file (no confirm for single files by default -can change in conf.rc)
r open file with program on rifle list
r 1 unpacks selected archive (need to install atool) -actually hits the 1st option with rifle (you can just type 1 Enter)
11,12,13,14 Enter (on image file) set image as desktop background with feh (11=scale, 12=tile, 13-center, 14=fill)
+ / - chmod commands
{octal no} = change permissions, e.g. 744 =, set permissions to -rwxr--r--


Space mark
v invert selection
V, uV marks/unmarks files as cursor moves, until escape pressed, or yanked etc (I change this to b)
u v unmark all files
t tag toggle
u t remove all tags
T remove any tags of selected files
"{x} custom tag
M.. linemode select (I change this to Alt-m)


Ctrl-R reload
Ctrl-h, z h toggle hidden files (I add to this F2)
Ctrl-c cancel an operation
Ctrl-s freeze ranger! Ctrl-c to continue
:flat 1 puts all files of sub-dir's (1 level deep) in the main column
z toggle settings
:, ; open console to enter commands
s, !, @, # open shell console
1? display all key bindings alphabetically
2? Ranger commands usage
3? Ranger settings
?, F1 man page, key bindings or settings
W message log
w job queue

Macros used in console and shell

%f the highlighted file
%d the path of the current directory
%s the selected files in the current directory. (defaults to highlighted file if none selected)
%t all tagged files in the current directory
%c the full paths of the currently copied/cut files
%p the full paths of the selected files

Flags used with open_with and shell commands

(type r for open_with, or s, !, @ for shell. open_with flags must be plain with no dash -)

-f runs process in background - useful for an encoding/mogrify job as ranger will still be usable while the process completes
-c runs on current file, not selected
-r runs with super user privileges
-t will show the process in a new terminal window (opens xterm)

Flags used with only the shell command

-p sends the process to the pager - which is closed with q, or canceled before with Ctrl-C
-s silent mode - the output is discarded
-w bash waits at the end of the process so that you can read the output and then press enter

typing '@-rf geany' will open a file with sudo (writes `shell -rf geany %s` to console)

Check the rc.conf file

My keybindings

Updated Aug 2018

keybinds I changed from the default..

Note: with Ranger 1.7 key mapping with Alt is (almost) fixed, e.g. <a-r>, which opens up a huge area for new keys! Still can't use <a-[> or <a-bracketleft> or <c-1>


then all those I added..

Alt-m metadata
f files
O open files
y/d/p yanking
P super user
X/x delete
dot-number config files
'; cd config dir's
,k backup
,l symlinks
,d directories
,a archives
,i iso
,s source files
F feh
fi image files
fim mogrify
E exiftool
fa audio files
fv video files
fG GPS Babel conversion
,n nfs
J Github
,z bashburn
G gpg encryption
R batch renaming

moving around


map Alt-m for metadata


map f for files


f2 script, duplicates file, puts suffix inside the file extension:

"f3" script, to rename the highlighted file with the selected file's name, keeping original extension

map O to open files


map y,d,p for yank, cut and paste commands


map P for commands with super user privelege


map X for delete commands


map dot for finding config files


map '; for cd to config dir's


map comma-k for backup commands/scripts


script for ,kp (as Ranger chokes on the date-time macros thinking they are its own)

(the k2 and k9 scripts are simple rsync commands - see my config migrate page)

map comma-l for symlink commands


map comma-d for directory commands


map comma-a for archive commands


map comma-i for iso/dvd commands


map comma-s for source file commands (though dropping to shell might be more advisable)


map F for feh image viewer commands


map fi for image file commands


map fim for mogrify commands


map E for exiftool and jhead commands


script for Ef, "exif-sort"

script for fD, "sort-files" (a very useful one to have when you've imported 400 clips from a video camera etc - no EXIF data)

map fv for video file commands


scripts tor ffmpeg conversion of flac to ogg/mp3 - but see audio file commands for oggenc


map fa for audio edit commands


map fG for GPS Babel conversion


map comma-m and comma-u for mounting/unmouning drives


There's a pmount plugin written by vifon which uses Alt-m {x} {n} to mount, but my pumount %f has got to be faster for unmounting

map comma-n for mounting nfs


map J for Jekyll and Github commands


map comma-z for bashburn commands


script for ,z3 "bashburn-links"

map G for GPG encryption commands


map R for file renaming commands

Rr: replace, Rs: find spaces, Ru: change case, Rp: prepend, Ra: append, Re: exif date, Rn: numbering, Rc: cut

Here's my complete Ranger renaming tool that just might take care of all your needs for naming files!

You might want to have these printed on a sheet because some commands are too long and a #comment will not be seen. You should also run some tests on dummy files - don't assume that they all work perfectly!!!


script for append file modified date (Ra3)

note the use of the parameter $@ which will hit all the files passed to bash script, not all the files in dir

script for image date prepend (Re1)

script for image date append (Re2)

script for append numbering (Ra4)
i=1 start from, 3d =digits, +1 =step

script for renaming images with date-time (Re3)

One problem is, however, with so many key-bindings, is the lack of sort-by-key in the command visual. They are sorted alphabetically by command, and so finding the one you want........ I split the renaming up so as to not fill up R with a huge mix up of commands.

Notes on mapping keys

Useful native commands

map / console search_inc (space after)which searches as you type, but no filtering like scout

map / console scout -ilt (space after)hit / and type pattern, searches as you type, missing letters out, can correct your search until right file is selected

scout options as listed in commands.py:

-a automatically open a file on unambiguous match
-e open file on hitting Enter
-f reduces file list to scout hits, (same as filter command does)
-g interpret pattern as a glob pattern
-i ignore case
-k keep the console open when changing a directory with the command
-l letter skipping; e.g. allow "rdme" to match the file "readme"
-m mark the matching files on hitting Enter
-M unmark the matching files on hitting enter
-p permanent filter on hitting Enter (unmatched files stay hidden)
-s smart case: lower case hits all, uppercase hits only uppercase
-t searches as you type
-v inverts the match

ready-made Ranger aliases for the `scout` command

alias filter scout -iprt
alias find scout -aet
alias mark scout -mr
alias unmark scout -Mr
alias search scout -rts
alias travel scout -aefikst

map | console filter%space followed by any string, filters file names, including extensions, case-sensitive

map \[ travel%space pretty much does `scout -efklt ` which will navigate into the dir filtered by typing part of a dir name, when Enter is pressed, and the console is kept open to allow you to search for the next dir to enter

map <a-a> enter_bookmark a will map Alt-a to go to bookmark a (same as using the ' with its list of bookmarks but more permanent)

find tagged files

map f" shell -p less ~/.config/ranger/tagged

set nano as editor

add this line to the end of your ~/.bashrc file

Adjusting rifle

To change how different files types are opened (or the numbered choices when you hit 'r') you need to look in Ranger's rifle.conf file

Open images in feh, fullscreen, slideshow with progress to next, change the line to this,

Change how audio files open, in a new terminal window

Opening office docs, set the version you are using, e.g.

In-line preview of images

To have images showing in the pager at right of file list, first install w3m w3m-img then enable image preview "set preview_images true" in conf.rc

To show image preview for videos, you must first install ffmpegthumbnailer and you need to uncomment the two lines starting "###video/*)" in scope.sh (and make sure you copy the Ranger 1.7 scope file to ranger config dir)

This only works with rxvt, rxvt-unicode, and xterm terminals - so I advise switching to URxvt. See my Rxvt-unicode page

Refine the info displayed for image files

To refine the info shown in pager for image files (because otherwise there's way too much info there and it runs off the screen and you don't want to hit `i` every time you need a useful exif data), add this line to scope.sh in ~/.config/ranger, for image mimetype:

Note, this is the newer version, for the 2016-12 Ranger git master

Refine the info displayed for video/audio files

I have mediainfo commands that can go in scope.sh file as well, and if you want to add more tags to the commands, you need to run

to put all the available tags into a file - and read that file to see what you can use - test them with:

mediainfo --inform="group;%tag%" file

mediainfo commands will print any extra characters placed outside the `%tag%` in the output, so I add some to denote tabs (>) and line breaks (^) and pipe the output to sed which converts them to real tab spaces and line breaks before sending to pager, so that the info that mediainfo returns from a file will be displayed nicely.. now that's clever :^)

Note, this is the newer version again..
(this all goes inside the mimetype "case" section, between lines "case" and "esac")

Note that "File_Modified_Date_Local" shows the date in local time, but "File_Modified_Date" shows it in UTC (GMT).

If certain file extensions don't show any info (eg ogg previously with ranger 1.6), you need to add a new case section:

then you hit 'zi' (`set preview_images!` as of 2016-12, or my zx key) to switch from preview to details - though you need to refresh the dir with Ctrl-r :(

Integrate system trash with bash

download the zipped file from git (on the right of page) https://github.com/andreafrancia/trash-cli

unzip it, enter the dir and run

trash-cli commands

trash-put trashes files and directories
trash-empty empty the trashcan(s). use flag --shred to wipe it
trash-list list trashed file
restore-trash restore a trashed file (trashed from the current dir)
trash-rm remove individual files from trash can
trash-empty 7 empties files trashed more than 7 days ago

with ranger, map the delete key - map shell -s trash-put %s
works a charm!

bookmark ~/.local/share/Trash/files to easily retrieve files

or you could map keys to the trash places for each disk partition, use `shell cd`

then to restore a file, select and yank with yy, then hit h (I change history key to lower case h from H) to return to the dir you just deleted the file, and pp to drop the file back and restore it there.

UI enhancements!

1. Remove "user@host" from the title bar

  • in ranger type `g R`
  • navigate to gui/widgets/ and highlight titlebar.py
  • type exactly: `@ gksu geany`
  • or if you have geany/editor mapped to a key, e.g. my `shell -f gksu geany %s` is mapped to Ps
  • in the file comment these lines (#), then save and quit/restart ranger

2. Adjust colour of title bar (dir path)

  • rsync -r /usr/local/lib/python2.7/dist-packages/ranger/colorschemes
  • ~/.config/ranger/
  • or in ranger type `gR`, `yy` on colorschemes and `pp` in ~/.config/ranger/
  • edit the color scheme default (backup first)
  • under "context.titlebar"
indent must be exact
change white in tab??

Mounting and browsing an android device

1. using SSH and the phone's wifi hotspot

  • get "SSHFS Droid" app
  • in the app settings: unselect require wifi, change p/w
  • start the ssh server with the app, and run the wifi hotspot
  • connect to the android hotspot on the linux box
  • make a directory to mount the device on with, e.g.
  • enable allow_other in /etc/fuse.conf
  • mount the android device with the command (noting the ip address that SSHFS Droid gives after linux box connects to the hotspot - in my case - this will vary every time if mobile data is turned on! (so turn it off)
  • now the device will be mounted at /mnt/phone, with /storage (i.e. SDcard, extSDcard) at top level
  • normal sshfs unmount is with
  • But Ctrl-C in the active sshfs window works to unmount ok.

Ranger mapping:

2. using mtp connection via usb cable

  • install mtp
  • make a dir in user home for a mount point
  • then connect the phone via usb and set file transfer to mtp
  • run `go-mtpfs ~/mount-point-dir`
  • unmount the device with `fusermount -u ~/mount-point-dir`

The following commands are used for checking the android's connection, and may not be necessary for connecting, but if the device will not mount, try detecting it first:

Ranger mapping:

Got there! Now go ahead and enjoy some real file management!

Next page:

Firewall - setting the network traffic firewall using iptables

Home | Content | Site Map | TOP