Summary of Linux commands commonly used by operation and maintenance personnel

osc_s7fsyuo1 2020-11-11 16:46:40
summary linux commands commonly used


As operation and maintenance personnel , These common commands have to be , Master these commands , You'll get twice the result with half the effort at work , Provide efficiency .

 It is commonly used by operation and maintenance personnel Linux Command summary

One . Files and directories

  1. cd command , Used to switch the current directory , Its parameter is the path of the directory to switch to , It could be an absolute path , It could be a relative path .
cd /home Get into '/ home' Catalog
cd .. Return to the previous directory
cd ../.. Returns the two directories above
cd Enter personal home directory
cd ~user1 Enter personal home directory
cd - Return to last directory 
  1. pwd command , Show work path
    [[email protected] ~]# pwd
    /root
  2. ls command , Command to view files and directories ,list The meaning of
ls  View files in directory 
ls -l Show file and catalog details 
ls -a List all documents , Contains hidden files 
ls -R List with contents of subdirectories ( Recursively list ), All files in the directory will be displayed 
ls [0-9] Display file and directory names with numbers 
  1. cp command , For copying files ,copy The meaning of , It can also copy multiple files to one directory at a time
-a : Copy file properties together 
-p : Copy along with the properties of the file , Instead of using the default , And -a be similar , Often used for backup 
-i : If the target file already exists , When you overwrite, you will first ask for the operation 
-r : Recursive continuous replication , Replication behavior for directories // Recursive replication is often used 
-u : Only when the target file is different from the source file will it be copied 
  1. mv command , For moving files 、 Catalog or rename ,move The meaning of
-f :force The meaning of coercion , If the target file already exists , Don't ask and cover directly 
-i : If the target file already exists , You will be asked if you want to overwrite 
-u : If the target file already exists , And newer than the target file , Will update 
  1. rm command , Used to delete files or directories ,remove The meaning of
-f : Namely force It means , Ignore nonexistent files , There will be no warning messages 
-i : Interactive mode , Before deleting, the user will be asked whether to operate 
-r : Recursive delete , Most commonly used for directory deletion , It's a very dangerous parameter 

Two 、 View file contents

  1. cat command , Used to view the contents of a text file , Followed by the name of the file you want to view , Usually, pipes and more and less Use it together
cat file1 View the contents of the file forward from the first byte 
tac file1 Reverse viewing the contents of a file from the last line 
cat -n file1 Number of lines indicating the 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 from 1000 Line start display , Show 1000 OK, later 
cat filename | head -n 3000 | tail -n +1000 Show 1000 Row to 3000 That's ok 
cat filename | tail -n +3000 | head -n 1000 From 3000 OK, let's start , Show 1000( It shows 3000~3999 That's ok )

3、 ... and . File search

  1. find command , Used to find the system
    find / -name file1 from '/' Start root file system search for files and directories
    find / -user user1 Search belongs to user 'user1' Files and directories for
    find /usr/bin -type f -atime +100 Search in the past 100 Execution files not used in days
    find /usr/bin -type f -mtime -10 Search in 10 Files created or modified in days
    whereis halt Show a binary 、 Source code or man The location of
    which halt Displays the full path of a binary or executable 

Delete greater than 50M The file of :

find /var/mail/ -size +50M -exec rm {} \;

Four . File permissions - Use "+" Set the permissions , Use "-" For cancellation

  1. chmod command , Change file / Folder permissions

    ls -lh Display permission
    chmod ugo+rwx directory1 Set up the owner of the directory (u)、 group (g) And others (o) Reading (r,4 )、 Write (w,2) And execution (x,1) Authority
    chmod go-rwx directory1 Delete Group (g) And others (o) Read and write permission to the directory 
  2. chown command , Change the owner of the document
    chown user1 file1 Change the owner property of a file 
    chown -R user1 directory1 Change the owner property of a directory and change the property of all files in the directory at the same time 
    chown user1:group1 file1 Change the owner and group properties of a file 

11.chgrp command , Change the user group to which the file belongs

chgrp group1 file1 Change the group of files 

5、 ... and . Text processing

  1. grep command , Analyze a line of information , If there is any information we need , Show that line , This command is usually used with the pipeline command , Used to filter the output of some commands and so on
grep Aug /var/log/messages In the file '/var/log/messages' Search for keywords in "Aug"
grep ^Aug /var/log/messages In the file '/var/log/messages' Find in "Aug" Words at the beginning
grep [0-9] /var/log/messages choice '/var/log/messages' All lines in the file that contain numbers
grep Aug -R /var/log/* In the catalog '/var/log' And subsequent search strings in the directory "Aug"
sed 's/stringa1/stringa2/g' example.txt take example.txt In the document "string1" Replace with "string2"
sed '/^$/d' example.txt from example.txt Delete all blank lines in file 
  1. paste command
paste file1 file2 Merge the contents of two files or two columns
paste -d '+' file1 file2 Merge the contents of two files or two columns , Intermediate use "+" distinguish 
  1. sort command
sort file1 file2 Sort the contents of two files 
sort file1 file2 | uniq Take out the union of two files ( Keep only one duplicate line ) 
sort file1 file2 | uniq -u Delete intersection , Leave other lines 
sort file1 file2 | uniq -d Extract the intersection of two files ( Leave only files that exist in both files )
  1. comm command
comm -1 file1 file2 Comparing the contents of two files only delete 'file1' Content contained 
comm -2 file1 file2 Comparing the contents of two files only delete 'file2' Content contained 
comm -3 file1 file2 Comparing the contents of two files only removes the common parts of two files 

6、 ... and 、 Packaging and compressing files

  1. tar command , Package the files , The default is not to compress , If the corresponding parameters are specified , It also calls the corresponding compressor ( Such as gzip and bzip etc. ) Compress and decompress
-c : New package file 
-t : See what file names are included in the contents of the package file 
-x : Unpacking or decompressing functions , Collocation -C( Capitalization ) Specify the directory to extract , Be careful -c,-t,-x Can't be in the same command at the same time 
-j : adopt bzip2 Support for compression / decompression 
-z : adopt gzip Support for compression / decompression 
-v : In compression / During decompression , Display the file name being processed 
-f filename :filename For the documents to be processed 
-C dir : Specify compression / Decompressed Directory dir

Compress :tar -jcv -f filename.tar.bz2 The name of the file or directory to be processed
Inquire about :tar -jtv -f filename.tar.bz2
decompression :tar -jxv -f filename.tar.bz2 -C The directory you want to unzip

bunzip2 file1.bz2 Unzip one called 'file1.bz2' The file of 
bzip2 file1 Compress one called 'file1' The file of 
gunzip file1.gz Unzip one called 'file1.gz' The file of 
gzip file1 Compress one called 'file1' The file of 
gzip -9 file1 Maximum compression 
rar a file1.rar test_file Create a 'file1.rar' My bag 
rar a file1.rar file1 file2 dir1 Simultaneous compression 'file1', 'file2' And directory 'dir1' 
rar x file1.rar decompression rar package 
zip file1.zip file1 Create a zip Compressed package of format 
unzip file1.zip Unpack one zip Format pack 
zip -r file1.zip file1 file2 dir1 Compress several files and directories into one zip Compressed package of format 

7、 ... and . System and shutdown ( To turn it off 、 Reboot and logout )

shutdown -h now Shutdown system (1) 
init 0 Shutdown system (2) 
telinit 0 Shutdown system (3) 
shutdown -h hours:minutes & Shut down the system at the scheduled time 
shutdown -c Cancel system shutdown at scheduled time 
shutdown -r now restart (1) 
reboot  restart (2) 
logout  Cancellation 
time  Measure an order ( I.e. procedure ) Execution time of 

8、 ... and 、 Process related commands

  1. jps command , Displays the... Of the current system java Process situation , And its id Number

jps(Java Virtual Machine Process Status Tool) yes JDK 1.5 The one provided shows all the current java process pid The order of , Simple and practical , It's very suitable for linux/unix Look at the current situation on the platform java Some simple cases of the process .

  1. ps command , It is used to select the process running status of a certain time point and output ,process The meaning of
-A : All the processes are shown 
-a : Not with terminal All the processes involved 
-u : Processes related to effective users 
-x : Generally speaking, it is related to a Parameters used together , More complete information can be listed 
-l : longer , In more detail PID The information listed in 
ps aux # View all process data of the system
ps ax # Check not with terminal All the processes involved
ps -lA # View all process data of the system
ps axjf # View the status along with a part of the process tree 
  1. kill command , Used to work towards (%jobnumber) Or something PID( Numbers ) Send a signal , It is usually with ps and jobs Command is used together

Command format : kill[ Command parameter ][ process id]

Command parameter :

-l The signal , If no signal number parameter is added , Then use “-l” The parameter lists all the signal names 
-a When processing the current process , There is no limit to the correspondence between the command name and the process number 
-p Appoint kill The command only prints the process number of the relevant process , Without sending any signals 
-s Specify to send a signal 
-u Designated user 

example 1: List all signal names
command :kill -l
Output :

[[email protected] test6]# kill -l
1) SIGHUP 2) SIGINT 3) SIGQUIT 4) SIGILL
5) SIGTRAP 6) 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) SIGWINCH
29) SIGIO 30) SIGPWR 31) SIGSYS 34) SIGRTMIN
35) SIGRTMIN+1 36) SIGRTMIN+2 37) SIGRTMIN+3 38) 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) SIGRTMIN+15 50) 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

explain :

Only the first one 9 Signals (SIGKILL) To terminate the process unconditionally , Other signaling processes have the right to ignore . Here are some common signals :

HUP 1 Terminal disconnection 
INT 2 interrupt ( Same as Ctrl + C)
QUIT 3 sign out ( Same as Ctrl + \)
TERM 15 End 
KILL 9 Mandatory termination 
CONT 18 continue ( And STOP contrary , fg/bg command )
STOP 19 Pause ( Same as Ctrl + Z)

example 2: Get the value of the specified signal

[[email protected] test6]# kill -l KILL
[[email protected] test6]# kill -l SIGKILL
[[email protected] test6]# kill -l TERM
[[email protected] test6]# kill -l SIGTERM
[[email protected] test6]#

example 3: First use ps Find the process , And then use kill kill

 command :kill 3268
[[email protected] 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
[[email protected] test6]# kill 3268 

example 4: Kill the process completely

 command :kill –9 3268 // -9  Force kill process 
  1. killall command , Send a signal to a process started by a command , Used to kill a process with the specified name

Command format : killall[ Command parameter ][ Process name ]

 Command parameter :
-Z Just kill the owner scontext The process of 
-e Matching process name is required 
-I Ignore lowercase 
-g Kill process groups instead of processes 
-i Interactive mode , Ask the user... Before killing the process 
-l List all known signal names 
-q Do not output warning messages 
-s Send the specified signal 
-v Whether the report signal is sent successfully 
-w Waiting for the process to die 
--help Display help information 
--version Show version show 

Example

1: Kill all processes of the same name 
killall nginx
killall -9 bash
2. Send the specified signal to the process 
killall -TERM ngixn perhaps killall -KILL nginx
  1. top command , yes Linux Common performance analysis tools , It can display the resource usage of each process in the system in real time , Be similar to Windows Task manager .

How to kill the process :

(1) The way of graphical interface 
(2)kill -9 pid (-9 Indicates forced close )
(3)killall -9  Name of program 
(4)pkill  Name of program 

Check the process port number :

netstat -tunlp|grep Port number 

From the original :https://www.jianshu.com/p/7c0df6fcfc71

版权声明
本文为[osc_s7fsyuo1]所创,转载请带上原文链接,感谢

  1. 【计算机网络 12(1),尚学堂马士兵Java视频教程
  2. 【程序猿历程,史上最全的Java面试题集锦在这里
  3. 【程序猿历程(1),Javaweb视频教程百度云
  4. Notes on MySQL 45 lectures (1-7)
  5. [computer network 12 (1), Shang Xuetang Ma soldier java video tutorial
  6. The most complete collection of Java interview questions in history is here
  7. [process of program ape (1), JavaWeb video tutorial, baidu cloud
  8. Notes on MySQL 45 lectures (1-7)
  9. 精进 Spring Boot 03:Spring Boot 的配置文件和配置管理,以及用三种方式读取配置文件
  10. Refined spring boot 03: spring boot configuration files and configuration management, and reading configuration files in three ways
  11. 精进 Spring Boot 03:Spring Boot 的配置文件和配置管理,以及用三种方式读取配置文件
  12. Refined spring boot 03: spring boot configuration files and configuration management, and reading configuration files in three ways
  13. 【递归,Java传智播客笔记
  14. [recursion, Java intelligence podcast notes
  15. [adhere to painting for 386 days] the beginning of spring of 24 solar terms
  16. K8S系列第八篇(Service、EndPoints以及高可用kubeadm部署)
  17. K8s Series Part 8 (service, endpoints and high availability kubeadm deployment)
  18. 【重识 HTML (3),350道Java面试真题分享
  19. 【重识 HTML (2),Java并发编程必会的多线程你竟然还不会
  20. 【重识 HTML (1),二本Java小菜鸟4面字节跳动被秒成渣渣
  21. [re recognize HTML (3) and share 350 real Java interview questions
  22. [re recognize HTML (2). Multithreading is a must for Java Concurrent Programming. How dare you not
  23. [re recognize HTML (1), two Java rookies' 4-sided bytes beat and become slag in seconds
  24. 造轮子系列之RPC 1:如何从零开始开发RPC框架
  25. RPC 1: how to develop RPC framework from scratch
  26. 造轮子系列之RPC 1:如何从零开始开发RPC框架
  27. RPC 1: how to develop RPC framework from scratch
  28. 一次性捋清楚吧,对乱糟糟的,Spring事务扩展机制
  29. 一文彻底弄懂如何选择抽象类还是接口,连续四年百度Java岗必问面试题
  30. Redis常用命令
  31. 一双拖鞋引发的血案,狂神说Java系列笔记
  32. 一、mysql基础安装
  33. 一位程序员的独白:尽管我一生坎坷,Java框架面试基础
  34. Clear it all at once. For the messy, spring transaction extension mechanism
  35. A thorough understanding of how to choose abstract classes or interfaces, baidu Java post must ask interview questions for four consecutive years
  36. Redis common commands
  37. A pair of slippers triggered the murder, crazy God said java series notes
  38. 1、 MySQL basic installation
  39. Monologue of a programmer: despite my ups and downs in my life, Java framework is the foundation of interview
  40. 【大厂面试】三面三问Spring循环依赖,请一定要把这篇看完(建议收藏)
  41. 一线互联网企业中,springboot入门项目
  42. 一篇文带你入门SSM框架Spring开发,帮你快速拿Offer
  43. 【面试资料】Java全集、微服务、大数据、数据结构与算法、机器学习知识最全总结,283页pdf
  44. 【leetcode刷题】24.数组中重复的数字——Java版
  45. 【leetcode刷题】23.对称二叉树——Java版
  46. 【leetcode刷题】22.二叉树的中序遍历——Java版
  47. 【leetcode刷题】21.三数之和——Java版
  48. 【leetcode刷题】20.最长回文子串——Java版
  49. 【leetcode刷题】19.回文链表——Java版
  50. 【leetcode刷题】18.反转链表——Java版
  51. 【leetcode刷题】17.相交链表——Java&python版
  52. 【leetcode刷题】16.环形链表——Java版
  53. 【leetcode刷题】15.汉明距离——Java版
  54. 【leetcode刷题】14.找到所有数组中消失的数字——Java版
  55. 【leetcode刷题】13.比特位计数——Java版
  56. oracle控制用户权限命令
  57. 三年Java开发,继阿里,鲁班二期Java架构师
  58. Oracle必须要启动的服务
  59. 万字长文!深入剖析HashMap,Java基础笔试题大全带答案
  60. 一问Kafka就心慌?我却凭着这份,图灵学院vip课程百度云