Summary of Linux common commands (recommended collection)
Some commonly used commands are collected here for viewing when needed, welcome to add. (The operations mentioned here are based on the CentOS system by default)
file management
directory operations
switch directorycd
view catalogls
- -lList file details or directly ll
- -aList all files and directories in the current directory, including hidden a(all)
Create a directorymkdir
- -pCreate a directory, if there is no parent directory, create p(parent)
output informationecho
print file to command line (view file)cat
Change the user who owns the filechown
change file groupchgrp
download filewget
Find a string in a text filegrep
Count the number of lines, words, and characters in the textwc
partially displayedmore/less
find filesfind / -name ‘auto.cnf’
create empty filetouch
copy filescp
move or renamemv
Delete Filesrm
- -rRecursive deletion, can delete subdirectories and files
- -fforce delete
delete empty directoryis rm
The tree structure displays the directory, and the tree package needs to be installedtree
show current directorypwd
Create link fileln
Display text file contents in pagesmore、less
Display file header and tail contenthead、tail
vim operation
enter the editorvi/vim, vim three modes: command mode, insert mode, edit mode. Use ESC or i or : to switch modes.
enter edit mode inserti
exit edit modeesc
Save: enter laterw
Exit: enter laterq
Exit without saving: enter laterq!
show line numberset number
Find the key==/xxxx== Press n to jump to the next one, shift+n to the previous one
Copy the line where the cursor is and paste ityyp
h (move one character left ←), j (next line ↓), k (up line ↑), l (move one character right →)
Packing and compression related commands
Compressiontar\gzip\bzip2
-carchive files
-xCompressed file
-zgzip compressed file
-jbzip2 compressed files
-vShow compression or decompression process v(view)
-fUse the file name
Example:
only package, no compression:tar -cvf /home/abc.tar /home/abc
Pack and compress with gzip:tar -zcvf /home/abc.tar.gz /home/abc
Pack and compress with bzip2:tar -jcvf /home/abc.tar.bz2 /home/abc
If you want to decompress, just replace the above command directlytar -cvf / tar -zcvf / tar -jcvfJust replace the "c" with "x".
Linux pipeline
Use the standard output of one command as the standard input of another command. That is to use several commands in combination, and the latter command divides the result of the previous command.
Example:
grep -r "close" /home/* | more Search all files in the home directory, including close files, and output them in pages.
File permission management
Three Basic Permissions
R: read, the value is expressed as 4
W: Write, the value is expressed as 2
X: Executable, the value is 1
[root@VM-16-2-centos ~]# ll
total 597952
-rw------- 1 root root 12387614 Aug 29 2021 apache-zookeeper-3.7.0-bin.tar.gz
-rw-r--r-- 1 root root 113304268 May 3 12:22 jdk-8u281-linux-x64.rpm
As shown above,jdk-8u281-linux-x64.rpmThe permissions of the file are ==-rw-r–r–, a total of ten characters, divided into four paragraphs.
The first character "-" indicates an ordinary file; this location may also appearlLink;dIndicates
the second, third and fourth characters of the directoryrw-Indicates the authority of the current user, so it is expressed as 4+2=6,
the fifth, sixth and seventh characters in numerical valuesr–Indicates the permissions of the current group, so it is expressed as 4,
the eighth and ninetieth characters in numerical valuesr–== indicates other user permissions, so it is expressed as 4 in numerical value,
so the authority to operate this file is expressed in numerical value as 644
change permissions
Change permissions:sudo chmod[u belongs to the user g belongs to the group o other users a all users] [+increase authority-decrease authority] [rwx] directory name
For example: there is a file filename, the permission is ==-rw-r----x==, change the permission value to ==-rwxrw-rx==, expressed as 765 in numerical value
sudo chmod u+x g+w o+r filenameIt can also be expressed numericallysudo chmod 765 filename
run the program
command line run
Run ==./filename==
quitctrl+c
Background process
runnohup command >out.file 2>&1 &
quitps -ef |grep keyword|awk '{print $2}'|xarg kill -9
Run as a service
Set bootsystemctl enable
start upsystemctl start
closuresystemctl stop
system related
system management commands
Display the detailed information of the specified file, more detailed than lsstat
Show online login userswho
Display the current operating userwhoami
show hostnamehostname
show system informationuname
Dynamically display information about the process that currently consumes the most resourcestop
Show momentary process statusps\ps-aux
View directory sizeyou -h /home(with unit display catalog information)
View disk sizedf -h(display disk information with units)
Check network statusifconfig
Test network connectivityping
Show network status informationnetstat
The command will not be used anymore, see the document such as:man seized
[root@VM-16-2-centos ~]# man grep
GREP(1) General Commands Manual GREP(1)
NAME
grep, egrep, fgrep - print lines matching a pattern
SYNOPSIS
grep [OPTIONS] PATTERN [FILE...]
grep [OPTIONS] [-e PATTERN | -f FILE] [FILE...]
……
clear screenclear
Rename the commandalias,like:alias showmeit="ps -aux", deactivate the use ofunaliax showmeit
kill processkill, you can first usepsortopcommand to view the id of the process, and then use the kill command to kill the process.kill -9force delete
firewall
View firewall statusfirewall-cmd --state
stop firewallsystemctl stop firewalld.service
Prohibit firewall from bootingsystemctl disable firewalld.service
shutdown and restart
shutdownshutdown -h now
-r shut down and restart
-h shut down without restarting
now shut down and
restart immediatelyreboot
shutdownhalt
Network Configuration
View network card informationifconfig
Network Configuration/etc/sysconfig/network-script/ifcfg-eth0
Configure network card/etc/udev/rules.d/70-persistent-net.rules
User Management
create useruseradd
set passwordpasswd
storage group account/etc/group
System User Profile/etc/passwd
Store passwords for user accounts/etc/shadow
Store the password of the user group account==/etc/gshadow==
usernameuseradd
usernameuserdel
usernameadduser
group namegroupadd
group namegroupdel
Set a password for rootpasswd root
su root
su - root
System environment variable==/etc/profile==
user environment variablesbash_profile
User environment variable ==.bashrc==
su userSwitch users, load the configuration file .bashrc
su - userSwitch user, load configuration file /etc/profile, load bash_profile
Change the user and user group of the file
sudo chown [-R] owner[:group] {File|Directory}
-rw-r--r-- 1 root root 113304268 May 3 12:22 jdk-8u281-linux-x64.rpm
For example: returnjdk-8u281-linux-x64.rpmas an example. Belongs to user root, group root
To switch the user and group to which this file belongs. command can be used.
sudo chown daley:java jdk-8u281-linux-x64.rpm
install software
How to download the rpm installation package
Installrpm -i jdk-XXX_linux-x64_bin.rpm
look uprpm -qa | grep jdk
the listrpm -qa | more
ubuntu dpkg 方式
查找dpkg -I | grep jdk
列表dpkg -I | more
安装dpkg -i jdk-XXX_linux-x64_bin.deb
yum way
searchyum search jdk
Installyum install java-11-openjdk.x86_64
deleteyum erase java-11 -openjdk.x86 64
configuration file/etc/yum.repos.d/CentOS-Base.repo
ubuntu apt-get 方式
搜索 apt・cache search jdk
安装apt-get install openjdk-9-jdk
删除apt-get purge openjdk-9-jdk
配置文件/etc/apt/sources. Iist
How to download compressed files
edit .bashrc
Environment variable configuration
Open the environment variable filevi /etc/profile
Configure environment variablesexport JAVA_HOME=/root/j d k-XXX_lin ux-x64
export PATH= J A V A H O M E / b i n : JAVA HOME/bin: J A V A H OME / bin:PATH
refresh configurationsource /etc/profile
Finally, everyone is welcome to ask questions and communicate.