Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the Linux commands commonly used by operation and maintenance personnel

2025-04-05 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article analyzes what Linux commands are commonly used by operation and maintenance personnel. The content is detailed and easy to understand. Friends who are interested in "what Linux commands are commonly used by operation and maintenance personnel" can follow the editor's train of thought to read it in depth. I hope it will be helpful to everyone after reading. Let's follow the editor to learn more about "what Linux commands are commonly used by operation and maintenance personnel".

As operation and maintenance personnel, these common commands have to be able to master these commands, which will get twice the result with half the effort and provide work efficiency.

one。 The file and directory cd command, which is used to switch the current directory, takes an argument to the path of the directory to which you want to switch, 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

Pwd command to display the work path [root@liangxu ~] # pwd/root

Ls command, the command to view files and directories, list ls to 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 under this directory will be displayed ls [0-9] shows the file name and directory name containing numbers

Cp command, used to copy files, copy meaning, it can also copy multiple files to a directory at one time-a: copy the characteristics of the file together with the attributes of the file-p: copy together with the file attributes, rather than using the default method, similar to-a, it is often used for backup-I: if the target file already exists, it will ask for the operation when overwriting-r: recursive continuous copy Replication behavior for directories / / Recursive copy-u is often used: the destination file is copied only when there is a difference between the target file and the source file

Mv command, used to move files, directories or renames, move-f: force forced meaning, if the target file already exists, will not ask but directly overwrite-I: if the target file already exists, it will ask whether to overwrite-u: if the target file already exists and is newer than the target file, it will be updated

Rm command, used to delete files or directories, remove-f: means force, ignoring files that do not exist, there will be no warning message-I: interactive mode, users will be asked whether to operate before deletion-r: recursive deletion, most commonly used for directory deletion, it is a very dangerous parameter

2. Cat command to view the contents of a text file, followed by the name of the file to be viewed Usually available pipes with more and less use cat file1 to view the contents of a file forward from the first byte tac file1 to view the contents of a file in reverse from the last line cat-n file1 marks 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 find command Find /-name file1 used to find the system starts from'/'to enter the root file system to search for files and directories 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。 File permissions-use "+" to set permissions, use "-" to cancel the chmod command, change file / folder permissions ls-lh display permissions chmod ugo+rwx directory1 set directory owner (u), group (g), and others (o) to read (rpd4), write (wpd2) and execute (x 1) permissions chmod go-rwx directory1 delete group (g) and others (o) read and write permissions to the directory

Chown command, change the owner of a file chown user1 file1 change the owner property of a file chown-R user1 directory1 change the owner property of a directory and change the properties of all files in that directory at the same time chown user1:group1 file1 change 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 the grep command, analyzing the information on a line, and displaying the line if there is any information we need, which is usually used with pipe commands Used 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" grep [0-9] / var/log/messages Select'/ var/log/messages' file all lines containing numbers grep Aug-R in file'/ var/log/messages' / var/log/* searches the directory'/ var/log' and subsequent directories for the string "Aug" sed's example.txt to delete all blank lines from the example.txt file by replacing "string1" with "string2" sed'/ ^ $/ d'in the example.txt file.

Paste commands paste file1 file2 to merge the contents of two files or columns paste-d'+ 'file1 file2 merges the contents of two files or columns, distinguished by "+" in the middle

Sort command sort file1 file2 to sort the contents of two files sort file1 file2 | uniq takes out the union of two files (only one duplicate line is retained) sort file1 file2 | uniq-u deletes the intersection and leaves other lines sort file1 file2 | uniq-d takes out the intersection of two files (leaving only files that exist in both files)

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

6. Tar command to package and compress files, which is not compressed by default. If the corresponding parameters are specified, it will also call corresponding compression programs (such as gzip and bzip) to compress and decompress-c: create a new packaged file-t: check which file names are contained in the packaged file-x: unpack or decompress the file, and you can specify the decompressed directory with-C (uppercase). 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 shutdown-c cancels the system shutdown-r now restart at a predetermined time (1) reboot restart (2) logout logout time calculates the execution time of a command (that is, a program)

8. Process-related commands 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.

Ps command, which is used to select and output the running status of processes at a certain point in time. Process-A: all processes are displayed-a: all processes not related to terminal-u: related processes of valid users-x: generally used with a parameter, can 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

The kill command, which is used to send 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 11) SIGSEGV 12) SIGUSR213 14) SIGALRM 15) SIGTERM 16) SIGCHLD 18) SIGCONT 19) SIGSTOP 20) SIGTTIN 22) SIGTTOU 23) SIGURG 24) SIGXCPU25) SIGXFSZ 26) SIGVTALRM 27) SIGPROF 28) SIGWINCH29) SIGIO 30) SIGSYS 34) SIGRTMIN35) SIGRTMIN+1 36) SIGRTMIN+2 37) SIGRTMIN+3 38) SIGRTMIN+439) SIGRTMIN+6 41) SIGRTMIN+7 41) SIGRTMIN+843 44) SIGRTMIN+10 45) SIGRTMIN+11 46) SIGRTMIN+1247 49) SIGRTMIN+15 50) SIGRTMAX-1451 52) SIGRTMAX-12 53) SIGRTMAX-11 54) SIGRTMAX-9 56) SIGRTMAX-8 57) SIGRTMAX-7 58) SIGRTMAX-659) SIGRTMAX-5 60) SIGRTMAX-4 61) SIGRTMAX-3 62) SIGRTMAX-263) 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.logroot 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

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 parameter:-Z kills only processes with scontext-e requires matching process name-I ignores lowercase-g kills process group rather than process-I interaction mode, asks the user before killing process-l lists all known signal names-Q does not output warning information-s sends specified signal-v report signal is sent successfully-w waits for process death-help display help information-version display version display

Example

1: kill all processes with the same name killall nginx killall-9 bash3. Sends the specified signal killall-TERM ngixn or killall-KILL nginx to the process

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 | what is the grep port number? Linux is a free-to-use and freely distributed UNIX-like operating system. It is a multi-user, multi-tasking, multi-threaded and multi-CPU operating system based on POSIX. Using Linux, you can run major Unix tools, applications and network protocols.

About the operation and maintenance staff commonly used Linux commands which are shared here, I hope that the above content can make you improve. If you want to learn more knowledge, please pay more attention to the editor's updates. Thank you for following the website!

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.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report