How to use the command 'ranger' (with examples)

How to use the command 'ranger' (with examples)

Ranger is a console file manager with VI key bindings. It provides a quick and efficient way to navigate and manage files and directories from the command line. This article will demonstrate the various use cases of the ‘ranger’ command.

Use case 1: Launch ranger

Code:

ranger

Motivation: The most basic use case of the ‘ranger’ command is simply to launch the file manager. This allows you to navigate through your files and directories using the VI key bindings.

Explanation: The command ‘ranger’ launches the ranger file manager with its default settings.

Example output:

After running the command, the ranger file manager will open, showing the current directory and its contents.

Use case 2: Show only directories

Code:

ranger --show-only-dirs

Motivation: Sometimes, you may only be interested in navigating and managing directories, rather than dealing with individual files. By using the ‘–show-only-dirs’ option, you can filter the file manager to display only directories.

Explanation: The ‘–show-only-dirs’ option is used to filter the contents displayed in the ranger file manager. When this option is used, only directories will be shown, excluding files.

Example output:

After running the command, the ranger file manager will open, displaying only directories in the current directory.

Use case 3: Change the configuration directory

Code:

ranger --confdir=path/to/directory

Motivation: By default, ranger uses a configuration directory located in the user’s home directory. However, there may be situations where you want to change the configuration directory, such as when using ranger on a shared system and you want to keep your own configuration separate.

Explanation: The ‘–confdir’ option allows you to specify a custom directory for the ranger configuration files. By providing the path to a directory, you can change the configuration directory to the specified location.

Example output:

After running the command, the ranger file manager will open, using the specified directory as the configuration directory.

Use case 4: Change the data directory

Code:

ranger --datadir=path/to/directory

Motivation: Similar to the previous use case, there may be instances where you want to change the data directory used by ranger. This can be useful when dealing with multiple installations of ranger or when you want to store data in a specific location.

Explanation: The ‘–datadir’ option allows you to specify a custom directory for the ranger data files. By providing the path to a directory, you can change the data directory to the specified location.

Example output:

After running the command, the ranger file manager will open, using the specified directory as the data directory.

Use case 5: Print CPU usage statistics on exit

Code:

ranger --profile

Motivation: If you are interested in monitoring the CPU usage of ranger while using it, you can enable the ‘–profile’ option. This can be useful for performance analysis and optimization.

Explanation: The ‘–profile’ option enables the profiling feature of ranger. When ranger is exited, it will print CPU usage statistics, providing insights into its resource consumption.

Example output:

After running the command and using ranger, CPU usage statistics will be printed on the console when exiting the file manager.

Conclusion:

The ‘ranger’ command is a powerful console file manager with VI key bindings. It allows you to efficiently navigate and manage files and directories from the command line. By exploring the various use cases covered in this article, you can make the most of ranger’s features and customize its behavior according to your needs.

Related Posts

How to use the command 'vite' (with examples)

How to use the command 'vite' (with examples)

The ‘vite’ command is used to create a Vite project in JavaScript.

Read More
How to use the command espeak (with examples)

How to use the command espeak (with examples)

The espeak command is a text-to-speech (TTS) engine that converts text into spoken words.

Read More
Working with squashfs filesystems (with examples)

Working with squashfs filesystems (with examples)

1: Create or append files and directories to a squashfs filesystem (compressed using gzip by default) mksquashfs path/to/file_or_directory1 path/to/file_or_directory2 .

Read More