Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the modern alternatives to basic Linux command line tools

2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

Editor to share with you what are the modern alternatives to the basic Linux command line tools. I hope you will gain something after reading this article. Let's discuss it together.

1. Ncdu as a substitute for du

The NCurses disk Utilization (ncdu) tool provides similar results to du, but in an interactive curses-based interface, it focuses on directories that take up more disk space.

Ncdu will take some time to analyze the disk and then display the results based on your most commonly used directory or file, 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

Use the arrow keys to navigate to each entry. If you press Enter on a directory entry, ncdu will display the contents of that directory:

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

You can use it to drill down to the directory and find out which files take up the most disk space, and use the left arrow key to return to the previous directory. By default, you can press d and use ncdu to delete the file, and it will confirm the deletion request with you before deleting it. If you want to disable this behavior to prevent accidents, use the-r option for read-only access: ncdu-r.

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

$sudo dnf install ncdu

To learn more about this tool, check out the ncdu page.

Https://dev.yorhel.nl/ncdu

two。 Htop as a substitute for top

Htop is an interactive process viewer similar to top, but it provides a better user experience out of the box. By default, htop displays the same metrics as top in pleasant colors.

By default, htop looks like this:

By contrast, top defaults to this:

In addition, htop provides system overview information at the top, a command bar at the bottom, you can use function keys to trigger commands, and you can press F2 to enter the settings interface to customize it. You can change its color, add or remove metrics, or change the display options of the overview bar.

Although you can achieve similar results through configuration for the latest version of top, htop provides a more reasonable default configuration, which makes it a beautiful and easy-to-use process viewer.

For more information about this project, see the htop home page.

Https://hisham.hm/htop/

3. Tldr as a substitute for man

The tldr command line tool displays simplified command usage information, mainly including examples. It acts as a client for the community project tldr pages.

This tool cannot replace man. Man pages are still the standard and complete source of information for many tools. In some cases, however, man provides too much information. Sometimes you don't need all the information about a command; you just try to remember the basic options. For example, the man page of the curl command has almost 3000 lines. In contrast, the tldr page for curl has only 40 lines, 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

TLDR is the abbreviation of the online slang term "too long; didn't read", which refers to the summary of a long article. This is a good name for the tool, because man pages, while useful, are sometimes too long.

In Fedora, the tldr client is written in Python. You can install it using dnf. To learn about other client options, see the tldr pages project page.

Https://tldr.sh/

In general, tldr tools need to access the Internet to look up tldr pages. The Python client in Fedora allows you to download and cache these pages for offline access.

To learn more about tldr, you can use tldr tldr.

4. Jq as a substitute for sed/grep

Jq is a command-line JSON processor, similar to sed or grep, but specifically designed to process JSON data. If you are a developer or system administrator who uses JSON in your daily tasks, this is an essential tool in your toolbox.

The main advantage of jq over general text processing tools such as grep and sed is that it understands the data structure of JSON and allows complex queries to be created using a single expression.

For example, suppose you try to find the name of the container 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"}}

If you use grep directly to find name, write as follows:

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

Grep returns all lines that contain the word name. You can add more options to grep to restrict it, and use some regular expression operations to find the name of the container. If you are using jq to get the results you want, you can use an expression to simulate the downward navigation data structure, as shown below:

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

This command provides the names of the two containers. If you are just looking for the name of the second container, you can add an array element index to the expression:

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

Because jq knows the data structure, it can provide the same results even if the file format changes slightly. As long as the format changes slightly, grep and sed may provide different results.

Jq has many features, and to introduce all of them, you need to write another article. For more information, see the jq project page, man page, or tldr jq.

Https://stedolan.github.io/jq/

5. Fd as a substitute for find

Fd is a simple and quick alternative to the find command. It is not intended to replace all the functionality provided by find; instead, it provides some reasonable default values that are useful in some cases.

For example, when searching for source code files in a directory that contains a Git repository, fd automatically excludes hidden files and directories, including. The .git directory and ignores the schema in the. gitignore file. In general, it searches faster and provides more relevant results on the first search.

By default, fd performs a case-insensitive pattern search in the current directory, and the output is colored. Using find for the same search requires you to provide additional command-line arguments. For example, to search for all markdown files (.md or .MD) in the current directory, the find command is as follows:

$find. -iname "* .md"

Use fd to do the same search:

$fd .md

In some cases, fd requires additional options; for example, if you want to include hidden files and directories, you must use the option-H, which is not needed in find.

Fd is available for many Linux distributions. You can install in Fedora using the standard repository by executing the following command:

After reading this article, $sudo dnf install fd-find, I believe you have a certain understanding of "what are the modern alternatives to basic Linux command line tools". If you want to know more about it, please follow the industry information channel. Thank you for reading!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report