1024programmer Java About java: 5 new Linux command line tools are useful

About java: 5 new Linux command line tools are useful

Improve old command line tools with new replacement tools.

In daily use of Linux/Unix systems, we need to use many command line tools to complete tasks, as well as understand and manage our systems, 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 announced 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 have retained the original idea, look, and feel.

These tools are excellent and essential to many system administrators’ workflows. However, in recent years, the open source community has developed many alternative tools with more disadvantages. Although some tools are beautiful and useless, some have greatly improved their practicality and become an excellent choice for modern systems. In this article, I will introduce five alternatives to the canonical Linux command line tools.

Replacement of du: ncdu

NCurses DiskUsage (ncdu) tool provides similar results to du, but its curses-based interactive interface can display the directories that consume the most disk space.

First Ncdu needs to spend some time analyzing the disk, and then displays the directories or files according to the most commonly used programs, as shown below:

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 to each effect using the arrow keys. If you press Enter on the selected result, ncdu will display the contents of the directory:

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

You can drill down into each directory 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 delete files by pressing the d key, but ncdu will ask for confirmation before deleting the file. If you want to disable deletion operations to avoid accidents, you can set read-only access through 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 code base:

$ sudo dnf install ncdu

For more information about this tool, see: https://dev.yorhel.nl/ncdu.

top replacement: htop

htop is an interactive process browser similar to top, providing a better user experience. By default, htop displays the same indicators as top, and they are ugly black and white.

The default htop is as follows:

Compared with the default top:

In addition, the top of htop also provides system overview information, and the command bar at the bottom displays 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 delete indicators, and change the display options of the overview bar.

Although the latest version of top can also achieve similar results through configuration, the default configuration provided by htop is more reasonable and is easier to use as a process browser.

For more information about this project, please view the htop homepage (https://hisham.hm/htop/).

Recommend a Spring Boot basic tutorial and practical examples:
https://github.com/javastacks…

man’s replacement: tldr

The tldr command line tool displays simplified command documentation, and most documentation provides examples. It is a client of tldr pages for my project (https://tldr.sh/).

This tool is not a replacement for man. Man pages remain the standard and incomplete source of information for many tools. However, in some cases, man has too much content. Sometimes, you don’t need all the information about a command. You just need to remember the basic options. For example, the man page for the curl command is almost 3,000 lines long.�In comparison, curl’s tldr is only 40 lines long, as shown below:

$ tldr curl

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

 - 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

The full name of TLDR is “too long; didn’t read” (too long; not read), which is an Internet buzzword indicating that the article is too long. This name is very suitable for this aggregation tool, because manpages, although very useful, are too long.

In Fedora, the tldr client is written in Python. You can use dnf installation. Regardless of the rest of the client options, see the tldr pages of my project (https://tldr.sh/).

Generally, tldr tools require access to the Internet to query tldr pages. The Python client in Fedora allows you to download and cache these pages for offline access.

For more information about tldr, run tldr tldr. In addition, the Linux series interview questions and answers have been completely organized. Search the Java technology stack on WeChat and send: Interview in the background, which can be browsed online.

An alternative to using sed/grep to find JSON data: jq

jq is a command line processor for JSON. Just like sed or grep, but primarily for processing JSON data. If you are a developer or system administrator who needs to work with JSON in your daily work, then this is an essential tool in your toolbox.

Compared with general-purpose text processing tools (such as grep and sed), the main advantage of jq is that it understands the JSON data structure and you can create simple queries through an expression.

For example, suppose you are trying to find the name of a container in the following 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"
   }
 }

If you use grep to query name indirectly, the consequences are:

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

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 through regular expression operations. When using jq to achieve the desired results, you only need to use an expression that simulates the downward navigation data structure, as shown below:

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

This command returns the names of both containers. If you only want to see the name of the second container, you can increment the array element index in the expression:

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

Because jq can understand the data structure, it can provide the same results even if the file format changes slightly. But for grep and se, slight changes in the format will have completely different consequences.

jq also has many functions, and I need to write another article to introduce all its functions. For more information, see the jq my project page (https://stedolan.github.io/jq/), manpages, or tldr jq.

Replacement of find: fd

fd is a simple and fast replacement for the find command. Its goal is not to replace the performance of find, but to provide some reasonable default values, which can be very useful in certain situations.

For example, when searching for source code files in a directory containing a Git code repository, fd automatically excludes hidden files and directories (including .git directories) and ignores patterns in .gitignore files. Typically, it enables faster queries and provides more relevant results.

By default, fd will perform a case-insensitive pattern search on the current directory and output black and white results. When performing the same search using find, you need to provide additional command line parameters. For example, to search for all markdown files (i.e. .md or .MD files) in the current directory, the find command is as follows:

$ find . -iname "*.md"$ find . -iname "*.md"

The following fd search may return the same results:

$ fd .md

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 -H option, which is not required for find.

fd is available on many Linux distributions. Installing fd in Fedora can use the standard code library:

$ sudo dnf install fd-find

For more information, please see fd’s GitHub repository (https://github.com/sharkdp/fd/).

Excellent alternatives and proven utilities

While I’m still used to using the old tools, especially when connecting to servers remotely, the new alternatives offer additional benefits and can be helpful in many situations. Specifically to help me manage and work on Linux desktops and laptops.

Do you use other tools to solve your workflow? Please leave a comment below.

Original text: https://opensource.com/articl…

Author: Ricardo Gerardi

Translator: Mengyue, editor: Tu Min

Produced by: CSDN (ID: CSDNnews)

Recommended recent hot articles:

1.1,000+ Java interview questions and answers compiled (2021 latest version)

2. Stop filling the screen with if/ else and try the strategy mode, it’s so delicious! !

3. Damn it! What is the new syntax for xx ≠ null in Java?

4.Spring Boot 2.5 is announced, the light mode is so explosive!

5. “Java Development Manual (Songshan Edition)” is newly released, download it quickly!

It feels good, don’t forget to like and repost!


In this case, fd will perform a case-insensitive pattern search on the current directory and output black and white results. When performing the same search using find, you need to provide additional command line parameters. For example, to search for all markdown files (i.e. .md or .MD files) in the current directory, the find command is as follows:

$ find . -iname "*.md"$ find . -iname "*.md"

The following fd search may return the same results:

$ fd .md

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 -H option, which is not required for find.

fd is available on many Linux distributions. Installing fd in Fedora can use the standard code library:

$ sudo dnf install fd-find

For more information, please see fd’s GitHub repository (https://github.com/sharkdp/fd/).

Excellent alternatives and proven utilities

While I’m still used to using the old tools, especially when connecting to servers remotely, the new alternatives offer additional benefits and can be helpful in many situations. Specifically to help me manage and work on Linux desktops and laptops.

Do you use other tools to solve your workflow? Please leave a comment below.

Original text: https://opensource.com/articl…

Author: Ricardo Gerardi

Translator: Mengyue, editor: Tu Min

Produced by: CSDN (ID: CSDNnews)

Recommended recent hot articles:

1.1,000+ Java interview questions and answers compiled (2021 latest version)

2. Stop filling the screen with if/ else and try the strategy mode, it’s so delicious! !

3. Damn it! What is the new syntax for xx ≠ null in Java?

4.Spring Boot 2.5 is announced, the light mode is so explosive!

5. “Java Development Manual (Songshan Edition)” is newly released, download it quickly!

It feels good, don’t forget to like and repost!


This article is from the internet and does not represent1024programmerPosition, please indicate the source when reprinting:https://www.1024programmer.com/about-java-5-new-linux-command-line-tools-are-useful/

author: admin

Previous article
Next article

Leave a Reply

Your email address will not be published. Required fields are marked *

Contact Us

Contact us

181-3619-1160

Online consultation: QQ交谈

E-mail: 34331943@QQ.com

Working hours: Monday to Friday, 9:00-17:30, holidays off

Follow wechat
Scan wechat and follow us

Scan wechat and follow us

Follow Weibo
Back to top
首页
微信
电话
搜索