Five new Linux command-line tools
Related Tags：1. Apsara Stack Agility Elastic Compute Service (Alibaba Cloud ZStack)
2. ZStack vs VMware vSphere
Abstract: In the daily use of Linux/Unix systems, we need to use many command line tools to complete the work, as well as understand and manage our system, such as using du to monitor disk utilization and top to display system resources. Some tools have a long history. For example, top was first released in 1984, while du's first appearance dates back to 1971.
In the daily use of Linux/Unix systems, we need to use many command line tools to complete the work, as well as understand and manage our system, such as using du to monitor disk utilization and top to display system resources. Some tools have a long history. For example, top was first released in 1984, while du's first appearance dates back to 1971.
Over the years, these tools have been modernized and ported to different systems, but overall they still retain the original idea, look and feel.
These tools are excellent and essential to the workflow of many sysadmins. But in recent years, the open source community has developed many more advantageous alternatives. While some tools are flashy, others greatly increase their usability and make them an excellent choice for modern systems. In this article, I'll introduce five alternatives to the standard Linux command line tools.
Alternative to du: ncdu
The NCurses DiskUsage (ncdu) tool provides similar results to du's, but its curses-based interactive interface shows the directories that are consuming the most disk space.
First Ncdu takes some time to analyze the disk, and then displays the directories or files in the order they are most commonly used.
You can navigate to each result with the arrow keys. If you press Enter on a selected result, ncdu will display the contents of that directory:
You can drill down into individual directories to find out which files are taking up the most disk space. Use the left arrow key to return to the previous directory. By default, you can press d to delete files, but ncdu will ask for confirmation before deleting files. If you want to suppress delete operations to prevent accidents, you can set read-only access with the -r option: ncdu -r.
ncdu is available for many platforms and Linux distributions. For example, you can use dnf to install it directly on Fedora from the official repository
Alternative to top: htop
htop is an interactive process browser similar to top that provides a better user experience. By default, htop displays the same metrics as top, in nice colors.
The default htop looks like this:
Compared to the default top:
In addition, the top of htop also provides overview information of the system, and the command bar at the bottom shows the function key commands. You can also press F2 to enter the settings page to customize the interface. In the settings page, you can change its color, add or remove metrics, and change the display options of the overview bar.
While recent versions of top can be configured to achieve similar results, the default configuration provided by htop is more reasonable and easier to use as a process browser.
man's alternative: tldr
The tldr command line tool shows command documentation that can be simplified, and most documentation provides examples. It is a client of the tldr pages project (https://tldr.sh/).
This tool is not a replacement for man. The man pages are still the canonical and complete source of information for many tools. However, in some cases, the content of man is too much. Sometimes, you don't need all the information about the command. You just need to remember the basic options. For example, the man page for the curl command is almost 3,000 lines long. By comparison, curl's tldr has only 40 lines, like this:
The full name of TLDR is "too long; didn'tread" (too long; unread), which is an Internet catchphrase that means the article is too long. The name is a perfect fit for this aggregation tool, as the manpages, while very useful, are too long.
In Fedora, the tldr client is written in Python. You can install using dnf. See the tldr pages project (https://tldr.sh/) for other client options.
Typically, tldr tools require internet access to query tldr pages. The Python client in Fedora allows you to download and cache these pages for offline access.
For more information on tldr, run tldr tldr.
Use sed/grep to find alternatives to JSON data: jq
jq is a command line processor for JSON. Like sed or grep, but mostly for working with JSON data. If you are a developer or sysadmin whose day-to-day tasks require working with JSON, this is an essential tool in your toolbox.
The main advantage of jq over general-purpose text processing tools such as grep and sed is that it understands JSON data structures and you can create complex queries with a single expression.
As an example, let's say you're trying to find the name of a container in the following JSON file:
If you use grep to query name directly, the result is:
grep will return all lines containing the word name. You can add some other options to grep to limit the query results and find the name of the container via regex manipulation. When using jq to get the desired result, you just need to use an expression that simulates navigating down the data structure like this:
The command returns the names of both containers. If you just want to see the name of the second container, you can add the array element index to the expression:
Because jq understands data structures, it can give the same results even with a slight change in the file format. But for grep and se, a slight change in format provides completely different results.
jq has many more features, I need to write another article to cover all its features. See the jq project page (https://stedolan.github.io/jq/), manpages or tldr jq for more information.
Find alternative: fd
fd is a simple and fast replacement for the find command. Its purpose is not to replace the functionality of find, but to provide some sensible defaults that can be very useful in certain situations.
For example, when searching for source code files in a directory containing a Git codebase, fd automatically excludes hidden files and directories (including .git directories) and ignores patterns in .gitignore files. In general, it queries faster and provides more relevant results.
By default, fd performs a case-insensitive pattern search against the current directory and outputs colored results. When using the same search with find, you need to provide additional command line arguments. For example, to search for all markdown files (ie. .md or .MD files) in the current directory, the find command looks like this:
And the following fd search can return the same result:
In some cases, fd also requires other options. For example, if you want the search to include hidden files and directories, you must use the option -H, but find does not.
fd is available for many Linux distributions. Install fd in Fedora to use the standard code base:
Excellent alternative and proven utility
While I'm still used to using the old tools, especially when connecting to servers remotely, the new alternatives provide additional benefits and are helpful in many cases. Especially helping me manage and work on Linux desktops and laptops.
Knowledge Base Team
Knowledge Base Team
Knowledge Base Team
Knowledge Base Team
Explore More Special Offers
50,000 email package starts as low as USD 1.99, 120 short messages start at only USD 1.00