The most complete newest commonly used Linux commands

Linux Command Collection

1. What symbol is used to represent the absolute path? What is the meaning of the current directory and the upper directory? What is the main directory? What
command is used to switch directories ?  Absolute path: such as /etc/init.d
 Current directory and upper directory: ./ …/
 Home directory: ~/
 Switch directory: cd
2. How to view the current process? How to perform exit? How to check the current path?
 View the current process: ps
 ps -l lists the process information related to this login;
 ps -aux queries the process information in the memory;
 ps -aux | grep * query* the detailed information of the process;
 top view the memory Dynamic information of the process;
 kill -9 pid to kill the process.
 Execute and exit: exit
 View the current path: pwd
3. View the commands of the file  vi file name # edit mode to view, can be modified

 cat file name# displays the content of all files
 more file name# displays the file content in pages
 less file name# is similar to more, it is better to page forward
 tail file name# only view the tail, you can also specify the number of lines
 head file name# only view the head, you can also specify the number of lines
4. List several commonly used Linux commands
5.  List the file list: ls [parameter -a -l]
6.  Create and remove directories: mkdir rmdir
 Used to display the last few lines of the file: tail, for example: tail -n 1000: display the last 1000 lines
 Pack: tar -xvf
 Pack and compress: tar -zcvf
 Search string: grep
 Display the current directory : Pwd creates an empty file: touch
 Editor: vim vi
7. How do you check the log?
There are many Linux commands for viewing logs: tail, cat, tac, head, echo, etc.
This article only introduces a few commonly used methods.
1. One of the
most commonly used viewing methods for
tail Command format: tail[Required parameter][Select parameter][File] -f cyclic reading
-q do not display processing information
-v display detailed processing information
-c<number> displayed Number of bytes
-n<number of lines> Display the number of lines
-q, --quiet, --silent Never output the first part of the given file name
-s, --sleep-interval=S and -f are used together, which means sleep for S seconds at the interval of each repetition.
For example:
tail -n 10 test.log Query the log of the last 10 lines at the end of the log;
tail -n +10 test. log queries all logs after 10 lines;
tail -fn 10 test.log loops to view the last 1000 lines of records in real time (the most commonly used),
usually with grep search, for example:
tail -fn 1000 test.log | grep'key the word '
amount of data is too large one-time query, you can turn the page view, such as:
tail -n 4700 aa.log | More -1000 can be multi-screen display (ctrl + f or spacebar shortcut keys) 2, head The head opposite to tail is to look at the number of log lines before
head -n 10 test.log to query the first 10 lines of logs in the log file;
head -n -10 test.log to query all logs except the last 10 lines of the log file;

For other parameters of head, refer to tail
3. cat
cat is displayed on the screen continuously from the first line to the last line
 Display the entire file at one time:
$ cat filename
 Create a file from the keyboard:
$cat> filename
 Combine several files into one File:
$cat file1 file2> file You can only create new files, not edit existing files.
 Append the content of one log file to another:
$cat -n textfile1> textfile2
 Clear a log file:
$cat: >textfile2
Note :> means create, >> means append. Don't get confused.
For other parameters of cat
,
please refer to tail 4. The more more command is a text filter based on the vi editor. It displays the content of the text file page by page in a full screen mode, and supports
keyword positioning operations in vi . There are several built-in shortcut keys in the more list, the commonly used ones are H (get help information), Enter (scroll down one
line), space (scroll down one screen), and Q (exit command). The more command reads the file from front to back, so the entire
file is loaded at startup .
This command displays one screen of text at a time, stops when the screen is full, and a prompt message appears at the bottom of the screen, giving
the percentage of the file that has been displayed so far : –More–(XX%)
 more syntax: more file name
 Enter down n lines, need to be defined, the default is 1 line  Ctrl f scroll down one screen
 Spacebar scroll down one screen
 Ctrl b return to the previous screen
 = output the line number of the current line
 :f output file Name and the line number of the current line
 v call the vi editor
! Command to call Shell, and execute the command
 q exit more
5. The sed
command can find a specific section of the log file, query according to a range of time, you can follow the line number and Time range query
According to the line number
sed -n '5,10p' filename So you can only view the 5th to 10th lines of the file.
According to the time period
sed -n'/2014-12-17 16:17:20/,/2014-12-17 16:17:36/p' test.log

6. When the less
less command queries the log, the general process is as
follows : less log.log
shift + G command to the end of the file and then input? Add the keywords you want to search for example? 1213
Press n to search up the keyword
shift+n reverse search keyword
less is similar to more, you can browse the file at will with less, and more can only move forward, not backward, and less
will not load the entire file before viewing .
less log2013.log View file
ps -ef | less ps View process information and display
history through less paging | less View command history usage records and display
less log2013.log log2014.log through less paging
Common command parameters for browsing multiple files :
less and Similar to more, you can browse files at will with less, while more can only move forward, not backward, and less
will not load the entire file before viewing .
 less log2013.log View file
 ps -ef | less ps View process information and display through less paging
 history | less View command history usage records and display through less paging
 less log2013.log log2014.log Browse multiple files
 Frequently used Command parameters:
 -b <buffer size> Set the size of the buffer
 -g only mark the last searched keyword
 -i ignores the case when searching
 -m displays the percentage of similar more commands
 -N displays the line number of each line
 -o <file name> saves the content of less output in the specified file
 -Q does not use Warning sound
 -s shows a row of continuous empty lines
 /string: the function to search "string" downwards
 ?string: the function to search "string" upwards
 n: repeat the previous search (related to / or? )
 N: Repeat the previous search in reverse (related to/or ?)
 b Turn one page back
 h Display the help interface
 q Exit the less command

Guess you like

Origin blog.csdn.net/weixin_55580097/article/details/114172601
Recommended