Summary of commonly used Linux commands for development

As a developer, these common commands must be mastered. Mastering these commands will get twice the result with half the effort and provide work efficiency.

1, Files and directories

The cd command is used to switch the current directory. Its parameters are the path of the directory to switch to, which can be absolute or relative.

cd /home get into '/ home' catalogue
cd .. Return to the previous directory 
cd ../.. Return to the upper two directories 
cd               Enter personal home directory 
cd ~user1 Enter personal home directory 
cd - Return to the last directory

pwd command, displaying the working path

[root@mailvip ~]# pwd
/root

ls command, the command to view files and directories, which means list

ls View files in directory 
ls -l Displays details of files and directories 
ls -a Lists all files, including hidden files
ls -R List together with the contents of the subdirectory (recursive list), which means that all files in the directory will be displayed 
ls [0-9] Displays the file and directory names that contain numbers

cp command is used to copy files, which means copy. It can also copy multiple files to a directory at one time

-a : Copy the properties of the file together
-p : Copy along with the properties of the file instead of using the default method, and-a Similar, often used for backup
-i : If the target file already exists, the operation will be queried first when overwriting
-r : Recursive continuous replication is used for directory replication behavior //Recursive replication is often used
-u : The target 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 rename, which means move

-f : force Mandatory means that if the target file already exists, it will not be queried but directly overwritten
-i : If the target file already exists, you will be asked whether to overwrite it
-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, which means remove

-f : namely force Ignore nonexistent files and no warning message will appear
-i : Interactive mode, the user will be asked whether to operate before deletion
-r : Recursive deletion is most commonly used for directory deletion. It is a very dangerous parameter

2, View file contents

cat command is used to view the contents of a text file followed by the file name to be viewed. It can usually be used with more and less through a pipeline

cat file1 View the contents of the file forward from the first byte 
tac file1 View the contents of a file in reverse from the last line 
cat -n file1 Indicates the number of lines in 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 Display from 1000 lines, and display the data after 1000 lines
cat filename | head -n 3000 | tail -n +1000  Display 1000 to 3000 lines
cat filename | tail -n +3000 | head -n 1000  Starting at line 3000, 1000 is displayed(3000 is displayed~3999 that 's ok)

3, File search

The find command is used to find the name of the system

find / -name file1 from '/' Start searching the root file system for files and directories 
find / -user user1 Search for users 'user1' Files and directories for 
find /usr/bin -type f -atime +100 Search for executables that have not been used in the past 100 days 
find /usr/bin -type f -mtime -10 Search for files created or modified within 10 days 
whereis halt Displays a binary file, source code, or man Location of 
which halt Displays the full path of a binary or executable file

Delete files larger than 50M:

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

4, File permissions - use "+" to set permissions, and "-" to cancel permissions

chmod command to change file / folder permissions

ls -lh Display permissions 
chmod ugo+rwx directory1 Set the owner of the directory(u),group (g)And others(o)To read( r,4 ),write(w,2)And Implementation(x,1)Permissions for 
chmod go-rwx directory1  Delete Group (g)With others(o)Read / write execute permissions on the directory

chown command to change the owner of the file

chown user1 file1 Change the owner attribute of a file 
chown -R user1 directory1 Change the owner attribute of a directory and change the attributes of all files in the directory at the same time 
chown user1:group1 file1 Change the owner and group properties of a file

chgrp command to change the user group to which the file belongs

chgrp group1 file1 Change the group of files

5, Text processing

grep command analyzes a line of information. If there is any information we need, it will be displayed. This command is usually used together with pipeline command to filter and process the output of some commands, etc

grep Aug /var/log/messages  In file '/var/log/messages'Find keywords in"Aug" 

grep ^Aug /var/log/messages In file '/var/log/messages'Find in to"Aug"Starting vocabulary 
grep [0-9] /var/log/messages choice '/var/log/messages' All lines in the file that contain numbers 

grep Aug -R /var/log/* In directory '/var/log' And subsequent directories"Aug" 

sed 's/stringa1/stringa2/g' example.txt take example.txt In file "string1" replace with "string2" 

sed '/^$/d' example.txt from example.txt Delete all blank lines from the file

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, with"+"distinguish

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 copy of duplicate lines) 
sort file1 file2 | uniq -u Delete the intersection and leave other rows 
sort file1 file2 | uniq -d Take out the intersection of two files(Only files that exist in both files are left)

comm command

comm -1 file1 file2 Compare the contents of two files and delete only 'file1' Content included 
comm -2 file1 file2 Compare the contents of two files and delete only 'file2' Content included 
comm -3 file1 file2 Compare the contents of two files and delete only the parts common to the two files

6, Packaging and compressing files

The tar command packages the files. By default, the files will not be compressed. If the corresponding parameters are specified, it will also call the corresponding compression programs (such as gzip and bzip) for compression and decompression

-c : New package file
-t : See what file names are included in the contents of the packaged file
-x : Unpacking or decompression functions can be matched-C((in uppercase) specify the directory to extract. Note:-c,-t,-x Cannot appear 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, the file name being processed is displayed
-f filename : filename For files to process
-C dir : Specify compression/Unzipped directory dir

Compression: tar -jcv -f filename.tar.bz2 file or directory name to be processed query: tar -jtv -f filename.tar.bz2 decompression: tar -jxv -f filename.tar.bz2 -C directory to be decompressed

bunzip2 file1.bz2 Unzip a file called 'file1.bz2'File 
bzip2 file1 Compress one called 'file1' File 
gunzip file1.gz Unzip a file called 'file1.gz'File 
gzip file1 Compress one called 'file1'File 
gzip -9 file1 Maximum compression 
rar a file1.rar test_file Create one called 'file1.rar' My bag 
rar a file1.rar file1 file2 dir1 Simultaneous compression 'file1', 'file2' And catalog 'dir1' 
rar x file1.rar decompression rar package

zip file1.zip file1 Create a zip Compressed package in format 
unzip file1.zip Unzip one zip Format compressed package 
zip -r file1.zip file1 file2 dir1 Compress several files and directories into one at the same time zip Compressed package in format

7, System shutdown (shutdown, restart and logout)

shutdown -h now Shut down the system(1) 
init 0 Shut down the system(2) 
telinit 0 Shut down the system(3) 
shutdown -h hours:minutes & Shut down the system at a predetermined time 
shutdown -c Cancel system shutdown at scheduled time 
shutdown -r now restart(1) 
reboot restart(2) 
logout cancellation 
time Measure the execution time of a command (i.e. 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 provided by JDK 1.5 to display the pid of all current java processes. It is simple and practical. It is very suitable for simply viewing some simple situations of current java processes on linux/unix platform.

ps command is used to select and output the process operation at a certain point in time. It means process

-A : All processes are displayed
-a : Not with terminal All processes related to
-u : Processes related to valid users
-x : General and a Parameters can be used together to list more complete information
-l : Longer, more detailed PID Information list for

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 the status of a part of the process tree

The kill command is used to send a signal to a job (% jobnumber) or a PID (number). It is usually used with ps and jobs commands

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

Command parameters:

-l Signal. If the number parameter of the signal is not added, it is used“-l"The parameter lists all signal names
-a When processing the current process, the correspondence between command name and process number is not limited
-p appoint kill The command prints only the process number of the related process without sending any signal
-s Specify send signal
-u Designated 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) 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 9th Signal (SIGKILL) can unconditionally terminate the process, and other signal processes have the right to ignore it.     The following are common signals:

HUP 1 Terminal disconnection
INT 2 Interrupt (same as Ctrl + C)
QUIT 3 Exit (same as Ctrl + \)
TERM 15 termination
KILL    9    Compulsory termination
CONT 18    Continue (with STOP contrary, fg/bg (command)
STOP    19    Pause (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 find the process with ps, 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: completely kill the process

Command: kill –9 3268 // -9 force kill process

Kill Command sends a signal to the process started by a command to kill the process with the specified name

Command format: kill [command parameter] [process name]

Command parameters:
-Z Kill only those who have scontext 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 information
-s Send the specified signal
-v Whether the report signal is successfully sent
-w Wait 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 to the process
    killall -TERM ngixn perhaps killall -KILL nginx

top command is a commonly used performance analysis tool under Linux. It can display the resource occupation 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)killall -9 Program name
(4)pkill Program name

View process port number:

netstat -tunlp|grep Port number
 

Source: jianshu.com/p/7c0df6fc71

Keywords: Java Back-end

Added by dr_overload on Fri, 12 Nov 2021 13:21:22 +0200