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
history
Command to view the commands that have been run.
Here ishistory
Command sample output.
# history
Figure 2: history command example
Slavehistory
The command output shows that the command execution time is not displayed. Is there a solution? Yes! Run the following command:
# HISTTIMEFORMAT="%d/%m/%y %T "
# history
If you want this change to take effect permanently, add the following line~/.bashrc
File:
export HISTTIMEFORMAT="%d/%m/%y %T "
Then, run:
# 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:history
Command output log
2. How to test the disk write speed?
One rowdd
The command script can be implemented.
# dd if=/dev/zero of=/tmp/output.img bs=8k count=256k conv=fdatasync; rm -rf /tmp/output.img
Figure 4:dd
Command 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 usedu
A simple single-line script of the command can be implemented,du
The command is used to obtain the space usage of a file.
# 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.
Availablestat
Command
# 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.
# 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: