This article is for everyone to share. It has compiled some Linux system commands commonly used in the daily development process and formed a frequently used high-frequency Linux quick check memo. I hope everyone has to help.
Shut down/restart/log off
##Common commands | Function |
shutdown -h now | Shut down immediately |
shutdown -h 10 | Shut down after 10 minutes |
shutdown -h 11:00 | 11:00 shutdown |
shutdown -h 10 | Shutdown at scheduled time (after 10 minutes) |
shutdown -c | Cancel shutdown at specified time |
shutdown -r now | Restart |
shutdown -r 10 | Restart after 10 minutes |
shutdown -r 11:00 | Scheduled restart |
reboot | Restart |
init 6 | Restart |
init 0 | Shut down immediately |
telinit 0 | Shut down |
poweroff | Shut down immediately |
halt | Shut down |
sync | Synchronize buff data to disk |
logout | Exit login Shell |
Notes: For example It is also a shutdown. What is the difference between shutdown, poweroff, halt, and init 0? If you are interested, you can find out for yourself. There is a difference between them.
System information and performance check
This command is actually used a lot, because once there is a problem with the system or background service, we often have to Log in to view, including a lot of system information, such as: system version, kernel version, processor architecture, computer name, environment variables, user status, load status, memory usage, disk information, processes, network connections...
Commonly used commands | Function |
##uname -a
View the kernel /OS/CPU Information |
|
uname -r
View kernel version |
|
uname -m
View processor architecture |
|
arch
View processor architecture |
|
hostname
View computer name |
|
who
Display the user who is currently logged in to the system |
|
who am i
Display the user who is logged in Name |
|
whoami
Display current user name |
|
cat /proc/version
View linux version Information |
|
cat /proc/cpuinfo
View CPU information |
|
cat /proc/interrupts
View interrupts |
|
cat /proc/loadavg
View system load |
|
uptime
View system operation Time, number of users, load |
|
env
View system environment variables |
|
lsusb -tv
View system USB device information |
|
lspci -tv
View system PCI device information |
|
lsmod
View loaded system modules |
|
grep MemTotal /proc/meminfo
View total memory |
|
grep MemFree / proc/meminfo
Check the amount of free memory |
|
free -m
Check the memory usage and swap area usage |
|
date
Display system date and time |
|
cal 2021
Display 2021 calendar |
|
top
Dynamic display of cpu/memory/process, etc. |
|
vmstat 1 20
Collect system status every 1 second, 20 times |
|
iostat
Check io read and write/cpu usage |
|
sar -u 1 10
Query cpu Usage (once per second, 10 times in total) |
|
sar -d 1 10
Query disk performance |
|
Disks and Partitions
These are some common commands that are closely related to daily use. In Windows systems, we can view them on the graphical interface with a click of the mouse, but in Linux we You should be proficient in using commands to view, such as: viewing various partition information, disk usage, file and directory size, various mounting and uninstalling...
Commonly used commands |
Function |
##fdisk -l | View all disk partitions |
swapon -s | View all swap partitions |
df -h | View disk usage and mount points |
df -hl | Check the remaining disk space |
du -sh /dir | Check the size of the specified directory |
du -sk * | sort -rn
| Display file and directory sizes from high to low |
mount /dev/hda2 /mnt/hda2 | Mount hda2 disk |
##mount -t ntfs /dev/sdc1 /mnt/usbhd1
Specify the file system type to mount (such as ntfs) |
|
mount -o loop xxx.iso /mnt/cdrom
Mount iso file |
|
mount /dev/sda1 /mnt/usbdisk
Mount usb disk/flash device |
| ##umount -v /dev/sda1
Uninstall by device name |
| umount -v /mnt/mymnt
Uninstall by mount point |
| fuser -km /mnt/hda1
Force uninstall (use with caution) |
|
##Users and user groups
Linux User groups and users themselves are also very important concepts in the system. This part of the command is mainly about: CRUD of users, CURD of user groups, and also includes checking users, switching users, changing passwords, checking user login logs...
Common commands
Function
|
| ##useradd codesheep
Create user
| userdel -r codesheep | Delete user
| usermod -g group_name user_name | Modify User's group
| usermod -aG group_name user_name | Add user to group
| usermod -s /bin/ksh -d /home/codepig –g dev codesheep | Modify the login shell, home directory and user group of user codesheep
| groups test | View test The group the user belongs to
| groupadd group_name | Create user group
| groupdel group_name | Delete user group
| groupmod -n new_name old_name | Rename user group
| su - user_name | Full switch Go to a user environment
| passwd | Change the password
| passwd codesheep | Modify the password of a user
| w | View active users
| id codesheep | View specified user information
| last | View user login log
| crontab -l | View the current user’s scheduled tasks
| cut -d: -f1 /etc/passwd | View all users in the system
| cut -d: -f1 /etc/group | View all groups in the system
|
Network and process management
As a back-end developer, these commands are most likely to be used, such as: view network, view connection, view port service, configure network card /Firewall/Routing Table/DNS, view and filter processes, collect system status, and some system performance monitoring and troubleshooting commands...etc. These commands are very useful when back-end development is connected to the company's server to troubleshoot problems, and they are used frequently.
Common commands |
Function |
ifconfig |
View network interface properties |
ifconfig eth0 |
View the configuration of a certain network card |
route -n |
View routing table |
netstat -lntp |
View all listening ports |
##netstat -antp | View all established connections |
netstat -lutp | View TCP/UDP status information |
ifup eth0 | Enable eth0 network device |
##ifdown eth0
Disable eth0 network device |
|
iptables -L
View iptables rules |
| ##ifconfig eth0 192.168.1.1 netmask 255.255.255.0
Configure ip address |
| dhclient eth0
Enable eth0 in dhcp mode |
| route add -net 0/0 gw Gateway_IP
Configure the default gateway |
| route add -net 192.168.0.0 netmask 255.255.0.0 gw 192.168.1.1
Configure static route to reach network '192.168.0.0/16' |
| route del 0/0 gw Gateway_IP
Delete static route |
| hostname
View host name |
| host www.codesheep.cn
Resolve host name |
| nslookup www.codesheep.cn
Query DNS records to see if domain name resolution is normal |
| ps -ef
View all processes |
|
ps -ef | grep codesheep
Filter out the process you need |
| kill -s name
Kill the process with the specified name |
| kill -s pid
Kill the process with the specified pid |
| top
Display process status in real time |
| vmstat 1 20
Collect system status every 1 second, 20 times |
| iostat
View io read and write/cpu usage |
| sar -u 1 10
Query cpu usage (once per second, 10 times in total) |
| sar -d 1 10
Query disk performance |
|
Common system service commands
We usually come across a lot of these commands, for example, when we install them ourselves It is commonly used when deploying various basic programming environments and services, such as installing JDK, MySQL database, redis cache, nginx server...
Commonly used commandsFunction |
|
##chkconfig --list
List system services |
service status |
View a service
| ##service start | Start a service
| service stop | Terminate a service
| service restart | Restart a service
| systemctl status | View a service
| systemctl start | Start a service
| systemctl stop | Terminate a service
| systemctl restart | Restart a service
| systemctl enable < Service name> | Turn on self-start
| systemctl disable | Turn off self-start
|
File and directory operations
These commands are all basic operations used in Linux systems. They are also some of the most frequently used commands, regarding file operations and directory operations. , about the path. For example: various high-frequency operations on files and directories, creating, viewing, searching, deleting, renaming, copying, soft links, quick positioning and searching... etc. They are all high-frequency practical commands.
Common commands |
Function |
cd |
Enter a directory |
##cd … | Return to the upper directory |
cd …/ … | Go back two levels to the directory |
cd | Enter the personal home directory |
cd - | Go back to the directory of the previous step |
pwd | Display the current path |
ls | View file directory list |
ls -F | View the contents of the directory (show whether it is a file or directory) |
ls - l | View detailed list of files and directories |
ls -a | View hidden files |
ls -lh | show permissions |
ls -lSr | more |
tree | View the tree structure of files and directories |
##mkdir
Create directory |
|
mkdir dir1 dir2
Create two directories at the same time |
|
mkdir -p /tmp/dir1/dir2
Create a directory tree |
|
rm -f file1
Delete the 'file1' file |
|
rmdir dir1
Delete the 'dir1' directory |
|
rm -rf dir1
Delete the 'dir1' directory and its contents |
|
rm -rf dir1 dir2
Delete both at the same time Directory and its contents |
|
mv old_dir new_dir
Rename/Move directory |
|
cp file1 file2
Copy files |
|
cp dir/* .
Copy all files in a directory to the current directory |
|
cp -a dir1 dir2
Copy directory |
|
cp -a /tmp/dir1 .
Copy a directory to the current directory |
|
ln -s file1 link1
Create a soft link pointing to the file/directory |
|
ln file1 lnk1
Create a soft link pointing to the file/ Physical link to the directory |
|
find / -name file1
Search for files/directories starting from the following directory |
|
find / - user user1
Search the files/directory of user user1 |
|
find /dir -name *.bin
Search for .bin in the directory/dir Files with suffix |
|
locate Keywords
Quickly locate files |
|
locate *.mp4
Find Files ending in .mp4 |
|
whereis halt
Display the path of a binary file/executable file |
|
which halt
Find binary files in the system directory |
|
chmod ugo rwx dir1
Set the directory owner (u), group (g) and others (o) read (r) write (w) execute (x) permissions |
|
chmod go-rwx dir1
Remove group (g) with others (o) Read, write and execute permissions on the directory |
|
chown user1 file1
Change the owner attribute of the file |
|
chown -R user1 dir1
Change the owner attribute of the directory |
|
chgrp group1 file1
Change the file group |
|
chown user1:group1 file1
Change the owner and group of the file |
|
File Viewing and Processing
This part of the command is mainly about file processing or text processing. For example, as a programmer, what we operate most is the code source file. Various fancy viewing, comparison, addition, deletion, replacement, merge... and a series of quick operations.
Common commands |
Function |
cat file1 | View the file content |
cat -n file1 |
View the content and mark the number of lines |
cat xxx.txt |
awk 'NR%2==1' |
tac file1 |
Look back at the file content starting from the last line |
more file1 |
View the contents of a long file |
less file1 |
Similar to the more command, but allows reverse operations |
head -2 file1 |
View the first two lines of the file |
tail -2 file1 |
After viewing the file Two lines |
tail -f /log/msg |
View the content added to the file in real time |
grep codesheep hello .txt |
Search for the keyword codesheep in the file hello.txt |
grep ^sheep hello.txt |
Search for the keyword codesheep in the file hello.txt Content starting with sheep |
grep [0-9] hello.txt |
Select all lines containing numbers in the hello.txt file |
sed 's/s1/s2/g' hello.txt |
Replace s1 in the hello.txt file with s2 |
sed '/^ $/d' hello.txt |
Remove all blank lines from the hello.txt file |
sed '/ *#/d; /^$/d' hello .txt |
Remove all comments and blank lines from the hello.txt file |
sed -e '1d' hello.txt |
From the file hello Exclude the first line in .txt |
sed -n '/s1/p' hello.txt |
View only the lines containing the keyword "s1" |
sed -e 's/ *$//' hello.txt |
Remove the last white space characters of each line |
##sed - e 's/s1//g' hello.txt | Delete only the word s1 from the document and keep all the rest |
##sed -n '1,5p;5q ' hello.txt
View the content from the first line to the fifth line |
|
sed -n '5p;5q' hello.txt
View Line 5 |
|
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, use " " to distinguish |
|
sort file1 file2
Sort the contents of the two files |
|
sort file1 file2
uniq |
| ##sort file1 file2
uniq -u |
| sort file1 file2
uniq -d |
| comm -1 file1 file2
Compare the contents of the two files (remove The contents of 'file1') |
| comm -2 file1 file2
Compare the contents of the two files (remove the contents of 'file2') |
| comm -3 file1 file2
Compare the contents of the two files (removing the common parts of the two files) |
|
Package Decompression
This part of the content is mainly about the packaging, compression and decompression of files or directories, involving several compression package formats and files. This part of the command is also used very, very frequently in daily life.
Common commandsFunction |
|
zip xxx.zip file
Compress to zip package |
##zip -r xxx.zip file1 file2 dir1 |
Compress multiple file directories into zip package
|
unzip xxx.zip |
Unzip the zip package
| ##tar -cvf xxx.tar file | Create uncompressed tar Package
| tar -cvf xxx.tar file1 file2 dir1 | tar multiple file directories
| tar - tf xxx.tar | View the contents of the tar package
| tar -xvf xxx.tar | Extract the tar package
| tar -xvf xxx.tar -C /dir | Extract the tar package to the specified directory
| tar -cvfj xxx.tar.bz2 dir | Create bz2 compressed package
##tar -jxvf xxx.tar.bz2 |
Decompress bz2 compressed package |
tar -cvfz xxx.tar.gz dir |
Create gzip compressed package |
##tar -zxvf xxx.tar.gz | Decompress gzip compressed package |
bunzip2 xxx.bz2 | Decompress bz2 compressed package |
##bzip2 filename
Compressed file | |
gunzip xxx.gz
Decompress the gzip compressed package |
|
gzip filename
Compressed file |
|
gzip -9 filename
Maximum compression |
|
Then next are some common package manager commands. First of all, everyone should know what a package manager is.
Let’s put it this way, if there is no such thing as a package manager, it is probably just software installation on the Linux system, and I am afraid that many users will be dissuaded, because a lot of software dependency processing will make people Crazy. Therefore, to put it simply, we can understand the package manager as a component used to provide support for software installation, uninstallation, upgrade, and query on Linux systems. Therefore, for users, it is generally a set of tool commands.
The most widely used example is Red Hat's package structure RPM package manager, which is used by systems such as RedHat and CentOS. Typical commands are rpm command and yum command; and then there is DPKG package manager. It is used in systems such as Debain and Ubuntu. Typical commands include the dpkg command and the apt software tool.
rpm package management commands
Common commands |
Function |
rpm -qa |
View installed rpm packages |
rpm -q pkg_name |
Query an rpm package |
rpm -q --whatprovides xxx |
Display which package the xxx function is provided by |
##rpm -q --whatrequires xxx | Display which package the xxx function depends on |
rpm -q --changelog xxx | Display the change record of the xxx package |
rpm -qi pkg_name | View the detailed information of a package |
rpm -qd pkg_name | Query the location of a package Provided documentation |
rpm -qc pkg_name | View the configuration file provided by the installed rpm package |
rpm -ql pkg_name | Check which files are installed in a package |
rpm -qf filename | Check which package a file belongs to |
rpm -qR pkg_name | Query package dependencies |
rpm -ivh xxx.rpm | Install rpm package |
rpm -ivh --test xxx.rpm | Test installation rpm package |
rpm -ivh --nodeps xxx.rpm | Ignore dependencies when installing rpm package |
rpm -e xxx | Uninstall package |
##rpm - Fvh pkg_name
Upgrade the rpm package that has been installed |
|
rpm -Uvh pkg_name
Upgrade the rpm package (will install it if not installed) |
|
rpm -V pkg_name
RPM package details verification |
|
yum package management command
Common commands
Function |
|
##yum repolist enabled
Display Available source repositories |
| yum search pkg_name
Search software package |
| yum install pkg_name
Download And install the software package |
| yum install --downloadonly pkg_name
Only download but not install |
| yum list
Display all packages |
| yum list installed
View the current system installed packages |
| yum list updates
View the list of packages that can be updated |
| yum check-update
View the package packages that can be upgraded |
## yum update |
Update all software packages
|
yum update pkg_name |
Upgrade the specified software package
|
yum deplist pkg_name |
List package dependencies
|
yum remove pkg_name |
Remove package
|
yum clean all |
Clear cache
|
yum clean packages |
Clear cached packages
| ##yum clean headers | Clear cached headers
|
| dpkg package management command
Commonly used Command
Function
|
##dpkg -c xxx.deb |
List the contents of the deb package
dpkg -i xxx.deb |
Install/update deb package |
##dpkg -r pkg_name | Remove deb package |
dpkg -P pkg_name | Remove the deb package (without retaining the configuration) |
dpkg -l | View the deb packages installed in the system |
dpkg -l pkg_name | Display the general information of the package |
dpkg -L pkg_name | View the files installed by the deb package |
dpkg -s pkg_name | View the detailed information of the package |
dpkg –unpack xxx.deb | Unpack the contents of the deb package |
| apt software tool |
Common commands
Function
| apt-cache search pkg_name | Search package
apt-cache show pkg_name | Get overview information of the package |
apt-get install pkg_name | Install/ Upgrade software package |
apt-get purge pkg_name | Uninstall software (including configuration) |
apt-get remove pkg_name | Uninstall software (excluding configuration) |
apt-get update | Update package index information |
apt-get upgrade | Update installed packages |
apt-get clean | Clear cache |
Related recommendations: " | Linux Video Tutorial" |
The above is the detailed content of A summary of hard-core high-frequency Linux commands (summary sharing). For more information, please follow other related articles on the PHP Chinese website!