Installing and Using Ranger

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

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

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

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

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.


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值