5 Modern Alternatives to Old Linux Command Line Tools

By using more modern alternatives alongside older command-line tools, you can enhance your experience and even boost productivity.

5 Modern Alternatives to Old Linux Command Line Tools

In everyday work on Linux/Unix, we utilize numerous command-line tools — for example, du for monitoring disk usage and system resources. Some of these tools have been around for quite some time. For instance, top was introduced in 1984, and the first release of du dates back to 1971.

Over the years, these tools have been upgraded and ported to various systems, but overall, they have not strayed far from their original versions, with little change in their appearance and usability.

These are excellent tools that many system administrators find essential. However, the community has developed alternative tools that offer additional benefits. Some simply have a modern, attractive interface, while others significantly improve usability. In this translation, we will discuss five alternatives to the standard Linux command-line tools.

1. ncdu vs du

NCurses Disk Usage (ncdu) is similar to du, but with an interactive interface based on the curses library. ncdu displays the directory structure that takes up most of your disk space.

ncdu scans the disk and then presents the results sorted by the most frequently used directories or files, for example:

ncdu 1.14.2 ~ Use the arrow keys to navigate, press ? for help
--- /home/rgerardi ------------------------------------------------------------
   96.7 GiB [##########] /libvirt
   33.9 GiB [###       ] /.crc
    7.0 GiB [          ] /Projects
.   4.7 GiB [          ] /Downloads
.   3.9 GiB [          ] /.local
    2.5 GiB [          ] /.minishift
    2.4 GiB [          ] /.vagrant.d
.   1.9 GiB [          ] /.config
.   1.8 GiB [          ] /.cache
    1.7 GiB [          ] /Videos
    1.1 GiB [          ] /go
  692.6 MiB [          ] /Documents
. 591.5 MiB [          ] /tmp
  139.2 MiB [          ] /.var
  104.4 MiB [          ] /.oh-my-zsh
   82.0 MiB [          ] /scripts
   55.8 MiB [          ] /.mozilla
   54.6 MiB [          ] /.kube
   41.8 MiB [          ] /.vim
   31.5 MiB [          ] /.ansible
   31.3 MiB [          ] /.gem
   26.5 MiB [          ] /.VIM_UNDO_FILES
   15.3 MiB [          ] /Personal
    2.6 MiB [          ]  .ansible_module_generated
    1.4 MiB [          ] /backgrounds
  944.0 KiB [          ] /Pictures
  644.0 KiB [          ]  .zsh_history
  536.0 KiB [          ] /.ansible_async
 Total disk usage: 159.4 GiB  Apparent size: 280.8 GiB  Items: 561540

You can navigate through the entries using the arrow keys. If you press Enter, ncdu will display the contents of the selected directory:

--- /home/rgerardi/libvirt ----------------------------------------------------
                         /..
   91.3 GiB [##########] /images
    5.3 GiB [          ] /media

You can use this tool to, for example, determine which files are taking up the most disk space. You can go back to the previous directory by pressing the left arrow key. With ncdu, you can delete files by pressing the d key. It will ask for confirmation before deletion. If you want to disable the delete feature to prevent accidental loss of valuable files, use the -r option to enable read-only mode: ncdu -r.

Ncdu is available for many platforms and Linux distributions. For example, you can use dnf to install it on Fedora directly from the official repositories:

$ sudo dnf install ncdu

2. htop vs top

Htop is an interactive process viewing utility similar to top, but it provides a more user-friendly experience out of the box. By default, htop shows the same information as top, but in a more visually appealing and colorful way.

By default, htop looks like this:

5 Modern Alternatives to Old Linux Command Line Tools
Unlike top:

5 Modern Alternatives to Old Linux Command Line Tools
Additionally, htop displays a summary of system information at the top, and a command execution panel using function keys at the bottom. You can customize it by pressing F2 to open the setup screen. In the settings, you can change colors, add or remove metrics, or modify the overview panel display options.

Although tweaking the settings of the latest versions of top can also achieve similar usability, htop provides convenient default configurations, making it more practical and easier to use.

3. tldr vs man

The command-line tool tldr displays simplified reference information about commands, mainly examples. It was developed by the community tldr pages project.

It's worth noting that tldr is not a replacement for man. It remains the canonical and most complete tool for outputting reference pages. However, in some cases, man can be excessive. When you don't need comprehensive information about a command, and just want to remember its basic usage options. For instance, the man page for the curl command contains nearly 3000 lines. The tldr page for curl is 40 lines long. A snippet looks like this:


$ tldr curl

# curl
  Transfers data from or to a server.
  Supports most protocols, including HTTP, FTP, and POP3.
  More information: .

- Download the contents of a URL to a file:

  curl http://example.com -o filename

- Download a file, saving the output under the filename indicated by the URL:

  curl -O http://example.com/filename

- Download a file, following [L]ocation redirects, and automatically [C]ontinuing (resuming) a previous file transfer:

  curl -O -L -C - http://example.com/filename

- Send form-encoded data (POST request of type `application/x-www-form-urlencoded`):

  curl -d 'name=bob' http://example.com/form
- Send a request with an extra header, using a custom HTTP method:

  curl -H 'X-My-Header: 123' -X PUT http://example.com
- Send data in JSON format, specifying the appropriate content-type header:

  curl -d '{"name":"bob"}' -H 'Content-Type: application/json' http://example.com/users/1234

... TRUNCATED OUTPUT

TLDR stands for "too long; didn't read": which means that some text was ignored due to its excessive length. The title fits this tool because man pages, while useful, can sometimes be overly verbose.

For Fedora, tldr was written in Python. You can install it using the dnf package manager. Usually, the tool requires internet access to function. However, the Python client for Fedora allows you to download and cache these pages for offline access.

4. jq vs sed/grep

jq is a command-line JSON processor. It is similar to sed or grep but specifically designed to work with JSON data. If you are a developer or system administrator who uses JSON regularly, this tool is for you.

The main advantage of jq over standard text-processing tools like grep and sed is that it understands the structure of JSON data, enabling you to create complex queries in a single expression.

For example, you are trying to find container names in this JSON file:

{
  "apiVersion": "v1",
  "kind": "Pod",
  "metadata": {
    "labels": {
      "app": "myapp"
    },
    "name": "myapp",
    "namespace": "project1"
  },
  "spec": {
    "containers": [
      {
        "command": [
          "sleep",
          "3000"
        ],
        "image": "busybox",
        "imagePullPolicy": "IfNotPresent",
        "name": "busybox"
      },
      {
        "name": "nginx",
        "image": "nginx",
        "resources": {},
        "imagePullPolicy": "IfNotPresent"
      }
    ],
    "restartPolicy": "Never"
  }
}

Run grep to search for the line name:

$ grep name k8s-pod.json
        "name": "myapp",
        "namespace": "project1"
                "name": "busybox"
                "name": "nginx",

grep returned all lines containing the word name. You can add a few more parameters to grep to narrow it down, and with some manipulation of regular expressions, find container names.

To achieve the same result using jq, simply write:

$ jq '.spec.containers[].name' k8s-pod.json
"busybox"
"nginx"

This command will output the names of both containers. If you are only looking for the name of the second container, add the array index to the expression:

$ jq '.spec.containers[1].name' k8s-pod.json
"nginx"

Since jq is aware of the data structure, it gives the same results even if the file format changes slightly. grep and sed may not work correctly in this case.

jq has many features, but describing them requires another article. For more information, refer to the project page jq or to tldr.

5. fd vs find

fd is a simplified alternative to the find utility. Fd is not intended to completely replace it: it comes with the most common settings pre-configured, defining a general approach to working with files.

For example, when searching for files in a Git repository directory, fd automatically excludes hidden files and subdirectories, including the .git directory, and also ignores patterns from the .gitignore file. Overall, it speeds up searches by providing more relevant results on the first try.

By default, fd performs case-insensitive searches in the current directory with colored output. The same search using the find command requires additional parameters to be entered in the command line. For example, to find all .md files (or .MD) in the current directory, you need to write the following find command:

$ find . -iname "*.md"

For fd, it looks like this:

$ fd .md

However, in some cases, fd also requires additional parameters: for example, if you want to include hidden files and directories, you should use the -H option, although this is typically not required during searches.

fd is available for many Linux distributions. In Fedora, you can install it like this:

$ sudo dnf install fd-find

You don't have to give up anything

Are you using new Linux command-line tools? Or are you exclusively sticking to the old ones? But most likely, you have a combo, right? Please share your experiences in the comments.

Advertising

Many of our clients have already appreciated the advantages of epic servers!
This virtual servers with AMD EPYC processors, CPU core frequency up to 3.4 GHz. The maximum configuration will allow you to go all out — 128 CPU cores, 512 GB RAM, 4000 GB NVMe. Hurry to order!

5 Modern Alternatives to Old Linux Command Line Tools

Source: habr.com

Buy reliable website hosting with DDoS protection, VPS VDS servers 🔥 Buy reliable website hosting with DDoS protection, VPS VDS servers | ProHoster