In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces "commonly used Linux command finishing". In daily operation, I believe that many people have doubts about the commonly used Linux command finishing problems. The editor consulted all kinds of data and sorted out simple and easy-to-use operation methods. I hope it will be helpful for you to answer the doubts about "commonly used Linux command finishing"! Next, please follow the editor to study!
one。 Files and directories
1. The cd command, which is used to switch the current directory, takes an argument to the path of the directory to be switched to, either absolute or relative.
Cd / home goes into the'/ home' directory cd.. Return to the previous directory cd.. /.. Return to the upper two-level directory cd enter the personal home directory cd ~ user1 enter the personal home directory cd-return to the directory where you were last time
2. Pwd command to display the work path
[root@mailvip ~] # pwd / root
3. Ls command, command to view files and directories, meaning list
Ls view the files in the directory ls-l shows the details of files and directories ls-a lists all files, including hidden files ls-R listed together with the contents of the subdirectory (recursively listed), which means that all files in that directory will be displayed ls [0-9] shows the file name and directory name containing numbers
4. Cp command, which is used to copy files, meaning copy, it can also copy multiple files to a directory at one time
-a: copy the characteristics of the file together-p: copy along with the attributes of the file, instead of using the default method, similar to-a, it is often used for backup-I: if the target file already exists, it will first ask for the operation-r: recursive continuous copy, for directory replication / / Recursive copy-u: copy only when there is a difference between the target file and the source file
5. Mv command, which is used to move files, directories, or rename, meaning move
-f: force force means that if the target file already exists, it will be overwritten without asking-I: if the target file already exists, it will be asked whether to overwrite-u: if the target file already exists and is newer than the target file, it will be updated.
6. Rm command, which is used to delete a file or directory, meaning remove
-f: means force. Ignore files that do not exist, and no warning message will appear.-I: interactive mode, which asks the user whether to operate before deletion.-r: recursive deletion, most commonly used for directory deletion, it is a very dangerous parameter.
Second, view the contents of the file
7. Cat command, which is used to view the contents of a text file, followed by the name of the file to be viewed. Pipes are usually used with more and less
Cat file1 view the contents of a file forward from the first byte tac file1 reverse view the contents of a file cat-n file1 mark the number of lines of a file more file1 view the contents of a long file head-n 2 file1 view the first two lines of a file tail-n 2 file1 view the last two lines of a file tail-n + 1000 file1 is displayed from line 1000 Display cat filename after 1000 lines | head-n 3000 | tail-n + 1000 displays 1000 lines to 3000 lines cat filename | tail-n + 3000 | head-n 1000 starts at line 3000 and displays 1000 lines (that is, lines 3000mm 3999)
three。 File search
8. Find command, which is used to find the system's
Find /-name file1 starts from'/'to search for files and directories in the root file system find /-user user1 search for files and directories belonging to user 'user1' find / usr/bin-type f-atime + 100 search for unused execution files find / usr/bin-type f-mtime-10 search files created or modified in 10 days whereis halt displays a binary file, Location of source code or man which halt displays the full path of a binary or executable file
Delete files greater than 50m:
Find / var/mail/-size + 50m-exec rm {}\
four。 Permissions for files-use "+" to set permissions and "-" to cancel
9. Chmod command to change file / folder permissions
Ls-lh display permissions chmod ugo+rwx directory1 sets the permissions of the owner (u), group (g), and others (o) of the directory to read (r) 4), write (w), and execute (x) 1). Chmod go-rwx directory1 delete group (g) and others (o) read and write permissions to the directory
10. Chown command to change the owner of the file
Chown user1 file1 changes the owner properties of a file chown-R user1 directory1 changes the owner properties of a directory and simultaneously changes the properties of all files in the directory chown user1:group1 file1 changes the owner and group properties of a file
11.chgrp command to change the user group to which the file belongs
Chgrp group1 file1 changes the group of files
five。 Text processing
12. Grep command, analyze the information of a line, and display the line if there is any information we need. This command is usually used with pipe commands to filter the output of some commands, etc.
Grep Aug / var/log/messages look for keywords "Aug" grep ^ Aug / var/log/messages in file'/ var/log/messages' look for words starting with "Aug" in file'/ var/log/messages' grep [0-9] / var/log/messages Select'/ var/log/messages' file all lines containing numbers grep Aug-R / var/log/* in directory'/ var/ Log' and the following directory search for the string "Aug" sed's example.txt stringa1 example.txt to replace "string1" in the example.txt file with "string2" sed'/ ^ $/ d 'example.txt to delete all blank lines from the example.txt file
13. Paste command
Paste file1 file2 merges the contents of two files or columns paste-d'+ 'file1 file2 merges the contents of two files or columns, distinguished by "+" in the middle
14. Sort command
Sort file1 file2 sorts the contents of two files sort file1 file2 | uniq retrieves the union of two files (only one duplicate line is retained) sort file1 file2 | uniq-u deletes the intersection, leaving other lines sort file1 file2 | uniq-d takes out the intersection of two files (leaving only files that exist in both files)
15. Comm command
Comm-1 file1 file2 compare the contents of two files delete only the contents contained in 'file1' comm-2 file1 file2 compare the contents of two files delete only the contents contained in' file2' comm-3 file1 file2 compare the contents of two files delete only the common parts of the two files
VI. Packing and compressing files
16. Tar command to package the file, which is not compressed by default. If the corresponding parameters are specified, it will also call the corresponding compression program (such as gzip and bzip) to compress and decompress.
-c: create a new packaged file-t: check which filenames are contained in the packaged file-x: unpack or decompress, which can be paired with-C (uppercase) to specify the unzipped directory Note-c filename filename: filename cannot appear in the same command at the same time-j: compress / decompress with the support of gzip-z: compress / decompress with the support of gzip-v: during the compression / decompression process, display the name of the file being processed-f file: filename as the file to be processed-C dir: specify the directory to compress / decompress
Compression: tar-jcv-f filename.tar.bz2 the name of the file or directory to be processed query: tar-jtv-f filename.tar.bz2 extract: tar-jxv-f filename.tar.bz2-C directory to be extracted
Bunzip2 file1.bz2 decompress a file called 'file1.bz2', bzip2 file1 extract a file called' file1', extract a file called 'file1.gz', extract a file called gzip file1, compress a file called' file1', gzip-9 file1, maximize the compression of rar a file1.rar test_file to create a package called file1.rar' rar a file1.rar file1 file2 dir1 and compress' file1' at the same time. 'file2' and directories' dir1' rar x file1.rar extract rar package zip file1.zip file1 create a zip format package unzip file1.zip extract a zip format package zip-r file1.zip file1 file2 dir1 compress several files and directories into a zip format package at the same time
seven。 System and shutdown (shutdown, restart, and logout)
Shutdown-h now shuts down the system (1) init 0 shuts down the system (2) telinit 0 shuts down the system (3) shutdown-h hours:minutes & shuts down the system at a predetermined time shutdown-c cancels the shutdown system at a predetermined time shutdown-r now restart (1) reboot restart (2) logout logout time calculates the execution time of a command (that is, a program)
VIII. Process-related commands
17. Jps command, which displays the java process of the current system and its id number
Jps (Java Virtual Machine Process Status Tool) is a command that displays the pid of all current java processes provided by JDK 1.5. It is simple and practical, and is very suitable for simply viewing some simple situations of the current java process on the linux/unix platform.
18. Ps command, which is used to select and output the running status of the process at a certain point in time, meaning process
-A: all processes are displayed-a: all processes not related to terminal-u: processes related to valid users-x: generally used with a parameter to list more complete information-l: longer List PID information in more detail ps aux # View all process data of the system ps ax # View all processes not related to terminal ps-lA # View all process data of the system ps axjf # View together with part of the process tree status
19. The kill command, which is used to transmit a signal to a job (% jobnumber) or a PID (number), which is usually used with the ps and jobs commands
Command format: kill [command parameters] [process id]
Command parameters:
-l signal, if you do not add the numbering parameter of the signal, use the "- l" parameter to list all the signal names-a when processing the current process, there is no restriction on the correspondence between the command name and the process number-p specifies that the kill command only prints the process number of the relevant process, and does not send any signal-s specified send signal-u specified user
Example 1: list all signal names command: kill-l output:
[root@localhost test6] # kill-l 1) SIGHUP 2) SIGINT 3) SIGQUIT 4) SIGILL 5) SIGABRT 7) SIGBUS 8) SIGFPE 9) SIGKILL 10) SIGUSR1 11) SIGSEGV 12) SIGUSR2 13) SIGPIPE 14) SIGALRM 15) SIGTERM 16) SIGSTKFLT 17) SIGCHLD 18) SIGCONT 19) SIGSTOP 20) SIGTSTP 21) SIGTTIN 22) SIGTTOU 23) SIGURG 24) SIGXCPU 25) SIGXFSZ 26) SIGVTALRM 27) SIGPROF 28) SIGIO 29) SIGPWR 31) SIGSYS 34) SIGRTMIN+1 36) SIGRTMIN+2 37) SIGRTMIN+4 39) SIGRTMIN+5 40) SIGRTMIN+6 41) SIGRTMIN+7 42) SIGRTMIN+8 43) SIGRTMIN+9 44) SIGRTMIN+10 45) SIGRTMIN+11 46) SIGRTMIN+12 47) SIGRTMIN+13 48) SIGRTMIN+14 49) SIGRTMAX-14 51) SIGRTMAX-13 52) SIGRTMAX-12 53) SIGRTMAX-11 54) SIGRTMAX-10 55) SIGRTMAX-9 56) SIGRTMAX-8 57) SIGRTMAX-7 58) SIGRTMAX-6 59) SIGRTMAX-5 60) SIGRTMAX-4 61) SIGRTMAX-3 62) SIGRTMAX-2 63) SIGRTMAX-1 64) SIGRTMAX
Description:
Only the ninth signal (SIGKILL) can terminate the process unconditionally, and other signal processes have the right to ignore it. Here are some common signals:
HUP 1 terminal disconnect INT 2 interrupt (same as Ctrl + C) QUIT 3 exit (same as Ctrl +\) TERM 15 terminates KILL 9 forcibly terminates CONT 18 continues (as opposed to STOP, fg/bg command) STOP 19 pauses (same as Ctrl + Z)
Example 2: get the value of the specified signal
[root@localhost test6] # kill-l KILL [root@localhost test6] # kill-l SIGKILL [root@localhost test6] # kill-l TERM [root@localhost test6] # kill-l SIGTERM [root@localhost test6] #
Example 3: first use ps to find the process, and then kill it with kill
Command: kill 3268 [root@localhost test6] # ps-ef | grep vim root 3268 2884 0 16:21 pts/1 00:00:00 vim install.log root 3370 2822 0 16:21 pts/0 00:00:00 grep vim [root@localhost test6] # kill 3268
Example 4: kill the process completely
Command: kill-9 3268 / /-9 forcibly kill the process
20. The killall command, which sends a signal to a process started by a command to kill a process with a specified name
Command format: killall [command parameters] [process name]
Command argument:-Z kills only processes with scontext-e requires matching process name-I ignores lowercase-g kills process group instead of process-I interaction mode Before killing the process, ask the user-l to list all known signal names-Q does not output warning information-s sends the specified signal-v report signal is sent successfully-w waits for the process to die-help display help information-version display version display
Example
1: kill all processes with the same name killall nginx killall-9 bash 2. Sends the specified signal killall-TERM ngixn or killall-KILL nginx to the process
21. Top command is a commonly used performance analysis tool under Linux, which can display the resource consumption of each process in the system in real time, similar to the task manager of Windows.
How to kill a process:
(1) graphical interface (2) kill-9 pid (- 9 indicates forced shutdown) (3) name of killall-9 program (4) name of pkill program
View the process port number:
Netstat-tunlp | grep port number. This is the end of the study on "sorting out common Linux commands". I hope I can solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.