Five interesting Linux Command Line skills

Source: Internet
Author: User

Five interesting Linux Command Line skills

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

Figure 1: 5 command line skills

Let's start a new series. Here we will also write some tips and write them clearly with as little space as possible.

 

1. We can use historyCommand to view the commands that have been run.

Here ishistoryCommand sample output.

  1. # history

Figure 2: history command example

SlavehistoryThe command output shows that the command execution time is not displayed. Is there a solution? Yes! Run the following command:

  1. # HISTTIMEFORMAT="%d/%m/%y %T "
  2. # history

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

  1. export HISTTIMEFORMAT="%d/%m/%y %T "

Then, run:

  1. # source ~/.bashrc

Command and option explanation:

  • History-view commands that have been run
  • HISTIMEFORMAT-set the time format environment variable
  • % D-day
  • % M-month
  • % Y-year
  • % T-Timestamp
  • Source-in short, the file content is sent to the shell for execution.
  • . Bashrc-BASH script file that runs when started interactively

Figure 3:historyCommand output log

 

2. How to test the disk write speed?

One rowddThe command script can be implemented.

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

Figure 4:ddCommand example

Command and option explanation:

  • Dd-convert and copy files
  • If =/dev/zero-specifies the input file. The default value is stdin (standard input)
  • Of =/tmp/output. img-specifies the output file. The default value is stdout (standard output)
  • Bs-size of the block for one read and write operation, in MB at maximum
  • Count-number of copies
  • Conv-use a comma-separated policy to convert files (for example, convert uppercase letters to lowercase letters, echo AA | dd conv = lcase)
  • Rm-delete files and directories
  • -Rf-(-r) recursively deletes directories and contents, and (-f) Forcibly deletes the contents without outputting confirmation information.

 

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

One useduA simple single-line script of the command can be implemented,duThe command is used to obtain the space usage of a file.

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

Figure 5: How to obtain disk space usage

Command and option explanation:

  • Du-estimate the space usage of the file
  • -Hsx-(-h) more readable format, (-s) summary output, (-x) skipping files from other file systems
  • Sort-sort text files by row
  • -Rf-(-r) outputs The comparison results in reverse order, and (-f) ignores case sensitivity.
  • Head-the first few lines of the output file

 

4. Obtain the detailed status information of a file.

AvailablestatCommand

  1. # Stat filename_ext (for example, stat abc.pdf)

Figure 6: obtain detailed information about a file

 

5. Show Help

The last tip is for those users. If you are an experienced user, you may not need it unless you want to have fun. Attackers may have Linux Command Line phobia. The following command will display a man manual page at random. For beginners, the advantage is that they will always learn new things and will not get bored.

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

Figure 7: view the random man manual page

Command and option explanation:

  • Man-Linux man Manual
  • Ls-List objects
  • /Bin-path of the system executable file
  • Shuf-random disruption of input content by line and Output
  • Head-the first few lines of the output file

This is all the content. If you know any similar skills, you can share them with us and we will post them on the website in your language.

Do not forget to leave valuable feedback in the comment box below. Keep in touch. You can likes or share this article to help us better spread the content.

Via: http://www.tecmint.com/5-linux-command-line-tricks/

Author: Avishek Kumar Translator: goreliu Proofreader: wxy

This article was originally translated by LCTT and launched with the Linux honor in China

Source: https://linux.cn/article-5485-1.html

This article permanently updates the link address:

Related Article

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.