There are many commands in Linux. With the options of various commands, there are really thousands. How do we remember these commands? The answer is only two words: multi-purpose. We don't have many commonly used linux commands. As long as we use and practice frequently, we will master them quickly. For some uncommon commands, you can use the man command to view the detailed usage and use it.
Output the value of string or variable at the terminal. The echo command has no options.
# Output string echo string # Output variable value echo $SHELL
Used to display and set the time or date of the system.
date supports formatted output time, and a "+" sign is required before the format string.
- %a. % a: output day of the week
- %b. % B: output month
- %c: Output current time
- %d: What day of the month
- %D: Output date, same as% m%d%y
- Output full date, same as% Y-%m-%d
- %H. % I: output 24-hour hours and 12 hour hours respectively
- %M: Output minutes
- %S: Output seconds
- %j: Number of days this year
date '+%a' #Output: IV. Thu date '+%A' #Output: Thursday, Thursday date '+%b' #Output: September, Sep date '+%B' #Output: September, September date '+%c' #Output: Thursday, September 2, 2021 22:23:54 date '+%d' #Output: 02 date '+%D' #Output: 09 / 02 / 21 date '+%F' #Output: 2021-09-02 date '+%H' #Output: 22 date '+%I' #Output: 10 date '+%M' #Output: 34 date '+%S' #Output: 43 date '+%j' #Output: 245
- -d. -- date = string: output the user-defined time instead of the current time. A time string is required after D.
- -s. -- set = string: set the time, followed by the set time string
- -r. -- Reference = file: the last modification time of the output file
- -u: Output UTC time.
date -d 20230911 #Output: Sunday, September 11, 2023 00:00:00 CST date -s 20230911 date #Output: Sunday, September 11, 2023 00:00:00 CST date -r test.txt #Output: Sunday, August 15, 2021 14:10:36 CST date -u #Output: Sunday, September 11, 2023 00:00:00 CST
Restart the system
Notify the hardware to stop all CPU functions, but remain powered on
Used to view the system kernel and version
- -a: View the complete kernel name, host name, kernel release and other information
uname -a #Output: Linux My-PC 3.10.0-1127.19.1.el7.x86_64 #1 SMP Tue Aug 25 17:23:54 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux
Displays the terminal information of the currently logged in user.
who #Output: root PTS / 0 2021-09-03 20:40 (220.127.116.11)
View login records of all systems
- -n NUM, - NUM: number of records displayed
- -F: Output login and logout time and date
last -2 #output # root pts/0 18.104.22.168 Thu Sep 2 21:53 still logged in # root pts/3 22.214.171.124 Mon Sep 11 00:15 still logged in last -n 2 #output # root pts/0 126.96.36.199 Thu Sep 2 21:53 still logged in # root pts/3 188.8.131.52 Mon Sep 11 00:15 still logged in last -2 -F #output # root pts/0 184.108.40.206 Thu Sep 2 21:53:26 2021 still logged in # root pts/2 220.127.116.11 Mon Sep 11 00:07:56 2023 - Mon Sep 11 00:15:05 2023 (00:07)
This command is used to display the commands executed in history. The default value is 1000. If 1000 are not enough, you can customize the HISTSIZE variable value in the / etc/profile file. When entering a command, we can quickly use the previous command by pressing the [up] key. These records are obtained from history. If you clear hisotry, press [up] and there will be no content.
history #output # 768 history # 769 man history # 770 ls # 771 ll # 772 man history # 773 history # ...... # Empty history history -c
That's how Linux should learn