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 interesting command lines of Linux

2025-04-10 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

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

This article is mainly about "what are the interesting command lines of Linux?" friends who are interested may wish to take a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn what are the interesting command lines of Linux.

Did you make the best use of Linux? For many Linux users, there are many useful features that seem to be tricks. Sometimes you need these skills. This article will help you make better use of some commands and perform their more powerful functions.

Figure 1:5 command line tips

Let's start a new series, where we will also write some tips and write clearly in as little space as possible.

1. We can use the history command to see which commands have been run.

Here is a sample output of the history command.

The code is as follows:

# history

From the output of the history command, it is clear that the execution time of the command has not been typed. Is there a solution? Yes, there is! Run the following command:

The code is as follows:

# HISTTIMEFORMAT= "% d/%m/%y% T"

# history

If you want this change to take effect permanently, add the following line to the ~ / .bashrc file:

The code is as follows:

Export HISTTIMEFORMAT= "d/%m/%y T"

Then, run in the terminal:

The code is as follows:

# source ~ / .bashrc

Interpretation of commands and options:

History-View commands that have been run

HISTIMEFORMAT-an environment variable that sets the time format

% d-days

% m-month

% y-year

% T-timestamp

Source-in short, send the contents of the file to shell for execution

.bashrc-script file that runs when BASH starts interactively

two。 How do I test the disk write speed?

This can be done with one line of dd command script.

The code is as follows:

# dd if=/dev/zero of=/tmp/output.img bs=8k count=256k conv=fdatasync; rm-rf / tmp/output.img

Interpretation of commands and options:

Dd-convert and copy fil

If=/dev/zero-specifies the input file, defaults to stdin (standard input)

Of=/tmp/output.img-specifies the output file, which defaults to stdout (standard output)

Bs-the block size of a read and write, with a maximum of MB

Count-number of copies

Conv-use a comma-delimited strategy to convert files (LCTT: for example, convert uppercase letters to lowercase, echo AA | dd conv=lcase)

Rm-Delete files and directories

-rf-(- r) recursively deletes the directory and its contents, (- f) forcibly deletes without outputting confirmation information

3. How do you get the six largest files that eat your disk space?

A simple one-line script using the du command can be implemented, and the du command is mainly used to get the space usage of the file.

The code is as follows:

# du-hsx * | sort-rh | head-6

Interpretation of commands and options:

Du-estimate the space usage of the file

-hsx-(- h) more readable format, (- s) summary output, (- x) files skipping other file systems

Sort-sorts text files by line

-rf-(- r) outputs the results of the comparison in reverse order, (- f) ignores case

Head-the first few lines of the output file

4. Get the detailed status information of a file

You can use the stat command

The code is as follows:

# stat filename_ext (for example: stat abc.pdf)

5. Show help

The last tip is for beginners, and if you are an experienced user, you may not need it unless you want to have fun with it. Starters may have Linux command line phobia, and the following command will randomly display a man man page. For beginners, the advantage is that they always learn something new and never get tired of it.

The code is as follows:

# man $(ls / bin | shuf | head-1)

Interpretation of commands and options:

Man-Linux man manual

Ls-list Fil

/ bin-path to the system executable file

Shuf-randomly scramble the input by line and output it

Head-the first few lines of the output file

At this point, I believe you have a deeper understanding of "what are the interesting command lines of Linux?" you might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

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

Wechat

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

12
Report