5 Modern Alternatives to Old Linux Command Line Tools

By using more modern alternatives along with older command line tools, you can have more fun and even increase your productivity.

5 Modern Alternatives to Old Linux Command Line Tools

In our day to day work on Linux/Unix, we use a lot of command line tools - like du to monitor disk usage and system resources. Some of these tools have been around for a long time. For example, top appeared in 1984, while the first release of du dates back to 1971.

Over the years, these tools have been modernized and ported to different systems, but in general they have not gone far from their first versions, their appearance and usability have not changed much either.

These are great tools that many system administrators need. However, the community has developed alternative tools that offer additional benefits. Some of them simply have a modern, beautiful interface, while others greatly improve usability. In this translation, we will talk about five alternatives to 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 analyzes the drive and then displays the results sorted by the most commonly used directories or files, like so:

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

The entries can be navigated 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 navigate to the previous directory by pressing the left arrow key. With ncdu, you can delete files by pressing the d key. It asks for confirmation before deleting. If you want to disable the delete feature to prevent accidental loss of valuable files, use the -r option to enable read-only access: ncdu -r.

ncdu is available for many Linux platforms and 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 viewer similar to top, but provides a nice user experience out of the box. By default, htop displays the same information as top, but in a more visual 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
In addition, at the top, htop displays an overview of the system, and at the bottom, a panel for running commands using the function keys. You can set it up by pressing F2 to open the setting screen. In the settings, you can change colors, add or remove metrics, or change how the overview pane is displayed.

While tweaking the settings of recent versions of top can also achieve similar usability, htop provides a handy default configuration that makes it more practical and easier to use.

3. tldr vs man

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

It's worth noting that tldr is not a replacement for man. It is still the canonical and most complete man page output tool. However, in some cases man is redundant. When you don't need exhaustive information about a particular command, you're just trying to remember the basic uses of it. For example, the man page for the curl command is almost 3000 lines long. The tldr page for curl is 40 lines long. Its fragment looks like this:


$ tldr curl

# curl
  Transfers data from or to a server.
  Supports most protocols, including HTTP, FTP, and POP3.
  More information: <https://curl.haxx.se>.

- Download the contents of an 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 means "too long; did not read": that is, some text was ignored because of its excessive verbosity. The name fits this tool because the man pages, while helpful, are sometimes too long.

For Fedora, tldr was written in Python. You can install it with dnf manager. The tool usually requires internet access to work. But the Fedora Python client 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 is specifically designed to work with JSON data. If you are a developer or system administrator who uses JSON for day to day tasks, this tool is for you.

jq's main advantage over standard word processing tools like grep and sed is that it understands the JSON data structure, allowing you to create complex queries in a single statement.

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 find the string 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 options to grep to limit it, and with some regex manipulation find container names.

To get the same result with jq, just write:

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

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

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

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

jq has many functions, but one more article is needed to describe them. For more information, please refer to 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 defaults to the most common settings that determine the 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 returning more relevant results on the first try.

By default, fd searches in a case-insensitive manner in the current directory with colored output. The same search using the find command requires additional options on the command line. For example, to find all .md (or .MD) files in the current directory, you would write the following find command:

$ find . -iname "*.md"

For fd it looks like this:

$ fd .md

But in some cases, fd also requires additional options: for example, if you want to include hidden files and directories, you must use the -H option, although this is usually not required when searching.

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

$ sudo dnf install fd-find

There is no need to give up something.

Are you using the new Linux command line tools? Or sit exclusively on the old ones? But most likely, you have a combo, right? Please share your experience in the comments.

As advertising

Many of our clients have already appreciated the benefits epic servers!
It is a virtual servers with AMD EPYC processors, CPU core frequency up to 3.4 GHz. The maximum configuration will allow you to come off to the fullest - 128 CPU cores, 512 GB RAM, 4000 GB NVMe. Hurry up to order!

5 Modern Alternatives to Old Linux Command Line Tools

Source: habr.com

Add a comment