5 Interesting command line tips in Linux

Source: Internet
Author: User

Do you make the most of Linux? For many Linux users, there are many useful features that appear to be skills. There are times when you will need these skills. This article will help you better use some of the commands to play their more powerful functions.

Figure 1:5 command line Tips

We start a new series, where we will write some tips and write them out in as little space as possible.

1. We can use the history command to view the commands that 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? Run the following command:

The code is as follows:

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

# History

If you want to make this change permanent, add a line to the ~/.BASHRC file as follows:

The code is as follows:

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

Then, run in the terminal:

The code is as follows:

# source ~/.BASHRC

Explanation of commands and options:

history– View the commands that have been run

histimeformat– setting the time format for environment variables

%d– Day

%m– Month

%y– years

%t– time Stamp

source– simply sends the contents of the file to the shell to execute

. bashrc–bash script files that run when they are started interactively

2. How do I test disk write speed?

One-line DD command script can be implemented.

The code is as follows:

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

Explanation of commands and options:

dd– Transform and copy files

if=/dev/zero– Specifies the input file, the default is stdin (standard input)

of=/tmp/output.img– Specifies the output file, the default is stdout (standard output)

bs– a read and write block size that can be measured in megabytes

count– Number of copies

conv– use a comma-delimited policy to convert a file (LCTT: for example, converting uppercase letters to lowercase, echo AA | dd conv=lcase)

rm– Delete files and directories

-rf– (-R) recursively deletes a directory and its contents, (-f) forcibly deletes without outputting acknowledgement information

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

A simple single-line script that uses the DU command is implemented, and the DU command is used primarily to get the space usage of the file.

The code is as follows:

# DU-HSX * | Sort-rh | Head-6

Explanation of commands and options:

Space usage of the du– estimate file

-hsx– (-h) easier to read format, (-s) Rollup output, (-X) skip files from other file systems

sort– sort text files by rows

-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 detailed status information for 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 those who get started, and if you're an experienced user, you probably don't need it unless you want to find fun. The beginner may have the Linux command line phobia, and the following command will randomly display a man's man page. For beginners, the advantage is always to learn something new and not get tired of it.

The code is as follows:

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

Explanation of commands and options:

Man–linux Man Handbook

ls– List Files

/bin– the path to the system executable file

shuf– randomly disrupts and outputs input content by line

head– the first few lines of the output file

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.