The “#” in the following information indicates that the operation is performed as the root user
The article directories
- 1. Df command
- 2. Free command
- 3. Head command
- 4. Tail instruction
- 5. The less command
- 6. Wc instruction
- 7. Date instruction (key)
- 8. CAL instruction
- Clear/CTRL + L command
- 10. Pipeline (Important)
1. Df command
- Function: View the disk space
- Grammar:
# df -h
-h
Indicates that size is displayed in a readable form
2. Free command
- Function: View memory usage
- Grammar:
# free -m
-m
Said toMB
View by unit
- The remaining truly usable memory is
1665MB
. Swap
: Used for temporary memory, when the system real memory is insufficient to temporarily use disk space as memory.
3. Head command
- Function: Displays the first n lines of a file. If n is not specified, the first 10 lines are displayed by default.
- Grammar:
# head -n File path
- 【n for number 】
4. Tail instruction
- Function 1: View the status of a file
n
Ok, ifn
Do not specify the default display after10
line - Grammar:
# tail -n Specifies the file path
n
It’s also numbers
- Role 2: Yes
tail
Command to view the dynamically changing contents of a file. - Grammar:
# tail -f File path
- This command is used to view many system logs.
5. The less command
- Function: View the file, output less content, press the auxiliary function key (number + Enter, space bar + up and down arrow key) to view more
- Grammar:
Less Specifies the file path to view
- In exit just press
q
Keys can be.
6. Wc instruction
Syntax: # wc-lwc Specifies the path of the file to be counted
-l
Said:lines
, the number of rows-w
Said:words
The number of words is judged by the number of blanks-c
Said:bytes
The number of bytes
7. Date instruction (key)
- Action: indicates operation time and date (read, set)
- Grammar 1:
# date
Output format: Sun Jan 3 11:33:01 CST 2021
- Syntax 2:
# date "+%F"
(equivalent to the# date "+%Y-%m-%d"
) Output form: 2020-01-03
- Grammar:
# date "+ % F % T"
Quotation marks indicate that”Year month day and hour minute second“Become an indivisible whole
Equivalent operations# date "+%Y-%m-%d %H:%M:%S"
Output form: 2021-01-03 11:31:33
- Syntax 4: Fetch before or after some time (backup)
# date -d "-1 day" "+%Y-%m-%d %H:%M:%S"
- Optional values for symbols: + (after) or – (before)
- Optional unit values: day, month, year
%F: indicates the complete year, month and day. %T: indicates the complete hour, minute and second. %Y: indicates the four-digit year0) %d: indicates the date (with a lead0) %H: represents the hour (with the leading0) %M: indicates minutes (with leading0) %S: indicates the number of seconds (with leading0)Copy the code
8. CAL instruction
- Function: used to operate the calendar
- Grammar 1:
# cal
Is equivalent to# cal -1
Outputs a calendar for the current month directly
- Syntax 2:
# cal -3
Output calendar of last month + current month + next month
- Grammar:
# cal -y
Year outputs a calendar for a particular year
Clear/CTRL + L command
- Function: Clears existing commands and results (information) on the terminal.
- Grammar:
clear
Or shortcut keys:ctrl + L
- Note that this command does not actually clear the previous information, but hides the previous information at the top and continues to view the previous information through the scroll bar.
10. Pipeline (Important)
- Pipeline operators:
|
- Purpose: Pipes can generally be used for “filtering”, “special”, “extended processing”.
- Syntax: pipes cannot be used alone. They must be used in conjunction with the instructions described above.
(1) Filtering case (100% used) : You need to query the document name that contains letter Y in the root directory.
ls / | grep y
Copy the code
- For the above command:
(1) with the pipe as the dividing line, the front command has an output, after the need to input, then filter, and finally output, popular speaking is the output in front of the pipe is the input of the command behind;
②grep
Instruction: mainly used for filtering
(2) special use case: through the operation of the pipeline method to achieve the equivalent effect of less (learn) by less view before a file, you can # less path Now through pipeline can also write like this: # cat path | less
③ Extension processing: please use the learned command, to count the total number of documents in a directory? A: # ls / | wc -l