Shut down/restart/log out

Common commands role
shutdown -h now Immediately shut down
shutdown -h 10 Power off after 10 minutes
shutdown -h 11:00 11:00 shutdown
shutdown -h +10 Scheduled shutdown (after 10 minutes)
shutdown -c Cancel shutdown at specified time
shutdown -r now restart
shutdown -r 10 Restart in 10 minutes
shutdown -r 11:00 Time to restart
reboot restart
init 6 restart
init 0 Immediately shut down
telinit 0 To turn it off
poweroff Immediately shut down
halt To turn it off
sync Buff data synchronization to disk
logout Logging Out of Shell
. .

View system information and performance

Common commands role
uname -a View the kernel, OS, and CPU information
uname -r Viewing the Kernel Version
uname -m View processor architecture
arch View processor architecture
hostname View computer Name
who The current login user is displayed
who am i Displays the login user name
whoami Displays the current user name
cat /proc/version View the Linux version information
cat /proc/cpuinfo Viewing CPU Information
cat /proc/interrupts View the interrupt
cat /proc/loadavg Viewing system Load
uptime View the system running time, number of users, and load
env View environment variables of the system
lsusb -tv View USB device information
lspci -tv View PCI device information
lsmod View the loaded system modules
grep MemTotal /proc/meminfo Viewing the Total Memory Capacity
grep MemFree /proc/meminfo View the amount of free memory
free -m View the memory usage and swap area usage
date Displays the system date and time
cal 2021 Displays the 2021 calendar
top Dynamic display of CPU/memory/process information
vmstat 1 20 System status is collected every second for 20 times
export LANG=zh_CN.utf-8 Set the coding
. .

Disks and partitions

Common commands role
fdisk -l View all disk partitions
swapon -s View all swap partitions
df -h View disk usage and mount points
df -hl Same as above
du -sh /dir View the size of a specified directory
du -sk * | sort -rn Displays file and directory sizes from highest to lowest
mount /dev/hda2 /mnt/hda2 Mount the hda2 plate
mount -t ntfs /dev/sdc1 /mnt/usbhd1 Specify file system type mount (such as NTFS)
mount -o loop xxx.iso /mnt/cdrom Mount the ISO file
mount /dev/sda1 /mnt/usbdisk Mount A USB disk or flash memory device
umount -v /dev/sda1 Uninstallation by device name
umount -v /mnt/mymnt Unload via mount points
fuser -km /mnt/hda1 Forced uninstallation (With caution)
. .

Users and user groups

Common commands role
useradd zhaoxiaobin Create a user
userdel -r zhaoxiaobin Delete user
usermod -g group_name user_name Example Modify a user group
usermod -aG group_name user_name Add a user to a group
Usermod -s /bin/ksh -d /home/zhaoxiaobin -g dev zhaoxiaobin Modify the login Shell, home directory, and user group of user zhaoxiaobin
groups test View the group of the test user
groupadd group_name Creating a User Group
groupdel group_name Deleting a User Group
groupmod -n new_name old_name Renames a user group
su – user_name Fully switch to a user environment
passwd Change password
passwd zhaoxiaobin Example Change the password of a user
w Viewing Active Users
id zhaoxiaobin View information about user zhaoxiaobin
last View user login logs
crontab -l View the scheduled tasks of the current user
cut -d: -f1 /etc/passwd View all users in the system
cut -d: -f1 /etc/group View all system groups
. .

Network and process management

Common commands role
ifconfig View the attributes of a network interface
ifconfig eth0 View the configuration of a network adapter
route -n Viewing the Routing Table
netstat -lntp View all listening ports
netstat -antp View established TCP connections
netstat -lutp View the TCP/UDP status
ifup eth0 Example Enable the eth0 network device
ifdown eth0 The eth0 network device is disabled
iptables -L View iptables rules
Ifconfig eth0 192.168.1.1 netmask 255.255.255.0 Configuring the IP Address
dhclient eth0 Enable eth0 in DHCP mode
route add -net 0/0 gw Gateway_IP Configuring the Default Gateway
Route add-net 192.168.0.0 netmask 255.255.0.0 GW 192.168.1.1 Configure a static route to network ‘192.168.0.0/16’
route del 0/0 gw Gateway_IP Deleting a Static Route
host www.zhaoxiaobin.net Resolving host names
nslookup www.zhaoxiaobin.net Query DNS records and check whether domain name resolution is normal
ps -ef Viewing All Processes
ps -ef | grep redis Filter out the processes you need
kill -s name Kill Specifies the name of the process
kill -s pid Kill Specifies the PID process
. .

Common system service commands

Common commands role
chkconfig –list List system services
Service < service name > status Viewing a service
Service < service name > start Start a service
Service < service name > stop Terminate a service
Service < service name > restart Restarting a service
Systemctl status < service name > Viewing a service
Systemctl start < service name > Start a service
Systemctl stop Terminate a service
Systemctl restart Restarting a service
Systemctl enable Enable self-start
Systemctl disable < service name > Turn off autostart
. .

File and directory operations

Common commands role
ls -F View the contents of a directory (is it a file or a directory?)
ls -lSr View a list of files and directories (in ascending file size)
tree View the tree structure of files and directories
mkdir dir1 dir2 Create two directories simultaneously
mkdir -p /tmp/dir1/dir2 Create multiple directories (including parent)
rmdir dir1 Delete the ‘dir1’ directory
mv old_dir new_dir Rename/move the directory
cp file1 file2 Copy the file
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 soft links to files/directories
ln file1 lnk1 Create a physical link to a file/directory
find / -name file1 Search files/directories from the following directory
find / -user user1 Search for the files/directories of user user1
find /dir -name *.bin Search for files with the. Bin suffix in directory /dir
find ~ -name “test*” Searches the specified directory by file name
Locate < key words > Quick File Location
locate *.mp4 Look for files at the end of.MP4
Whereis < keyword > Displays the path to a binary/executable file
Which < key words > Find a binary file in the system directory
chmod ugo+rwx dir1 Set the read (r) write (W) execute (X) permissions of the directory owner (u), group (G), and others (O)
chmod go-rwx dir1 Remove the read/write permissions of groups (g) and others (O) on directories
chown user1 file1 Change the owner attribute of a file
chown -R user1 dir1 Change the owner attribute of a directory
chgrp group1 file1 Changing file Groups
chown user1:group1 file1 Change the owner and group of the file
scp start.sh [email protected]:/home/zxb Upload a file
scp -r testdir [email protected]:/home/zxb Upload directory
scp [email protected]:/home/zxb/start.sh /home/zxb The download file
scp -r [email protected]:/home/zxb/testdir /home/zxb Download directory
. .

File viewing and processing

Common commands role
cat file1 Viewing file Contents
cat -n file1 View the content and indicate the number of lines
tac file1 Look back at the file from the last line
more file1 View the contents of a long file
less file1 Similar to the more command, but allows the reverse operation
head -2 file1 Look at the first two lines of the file
tail -2 file1 Look at the last two lines of the file
tail -f /log/msg View the content added to the file in real time
grep hello hello.txt Look for the keyword hello in the file hello.txt
grep ^hello hello.txt Look for anything that begins with Hello in the file hello.txt
grep [0-9] hello.txt Select all the lines in the hello.txt file that contain numbers
grep -r “str” ./ Finds the string -c in the specified directory and counts the number of occurrences
sed ‘s/s1/s2/g’ hello.txt Replace s1 with S2 in hello.txt
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 Exclude the first line from the file hello.txt
sed -n ‘/s1/p’ hello.txt View the row that contains only the keyword “s1”
sed -e ‘s/ *$//’ hello.txt Remove the whitespace character at the end of each line
sed -e ‘s/s1//g’ hello.txt Remove only s1 from the document and keep all the rest
Sed – n ‘1, 5 p; 5q’ hello.txt Look at lines 1 through 5
sed -n ‘5p; 5q’ hello.txt Look at line 5
paste file1 file2 Combine the contents of two files or columns
paste -d ‘+’ file1 file2 Combine the contents of two files or columns separated by a “+”
sort file1 file2 Sort the contents of two files
comm -1 file1 file2 Compare the contents of two files (remove contents contained in ‘file1’)
comm -2 file1 file2 Compare the contents of two files (excluding ‘file2’)
comm -3 file1 file2 Compare the contents of two files (excluding the common parts of both files)
. .

Pack and unpack

Common commands role
zip xxx.zip file Zip to a ZIP package
zip -r xxx.zip file1 file2 dir1 Compress multiple files + directories into ZIP packages
Unzip swagger 1.0. Jar. Zip – d.. / Decompress the file to the specified directory
tar -cvf xxx.tar file Create an uncompressed tar package
tar -cvf xxx.tar file1 file2 dir1 Tar multiple files and directories
tar -tf xxx.tar View the content of the tar package
tar -xvf xxx.tar Unpack the tar packages
tar -xvf xxx.tar -C /dir Decompress the tar package to a specified directory
tar -jcvf xxx.tar.bz2 dir Create the BZ2 zip package
tar -jxvf xxx.tar.bz2 Decompress the BZ2 package
tar -zcvf xxx.tar.gz dir Create a gzip package
tar -zxvf xxx.tar.gz Decompress the gzip package
bunzip2 xxx.bz2 Decompress the BZ2 package
bzip2 filename The compressed file
gunzip xxx.gz Decompress the gzip package
gzip filename The compressed file
gzip -9 filename Maximum compression
. .

A firewall

Common commands role
firewall-cmd –zone=public –add-port=xxxx/tcp –permanent Open port
firewall-cmd –zone=public –add-port=xxxx-xxxx/tcp –permanent Enable ports in a specified range in batches
firewall-cmd –zone= public –remove-port=xxxx/tcp –permanent Delete ports
firewall-cmd –query-port=xxxx/tcp Query whether the port number is enabled
firewall-cmd –reload Restarting the Firewall
firewall-cmd –list-port Query which ports are enabled
service firewalld start Start the firewall
service firewalld stop Disabling the Firewall
service firewalld status Checking the Firewall Status
systemctl enable firewalld Starting the Firewall
systemctl disable firewalld Do not start the firewall upon startup
. .

crontab

Common commands role
crontab -e Edit the crontab service for a user
0 0 * * * sh $HOME/nginx/logs/clear_nginx_log.sh Execute scripts every morning
crontab -l Lists the details of a user’s CRon service
service crond status Check the CRon service status
. .

RPM package management command

Common commands role
rpm -qa Check the installed RPM packages
rpm -q pkg_name Example Query an RPM package
rpm -q –whatprovides xx Shows which package XXX functionality is provided by
rpm -q –whatrequires xxx Shows which package the XXX function is dependent on
rpm -q –changelog xxx Displays change records for XXX package
rpm -qi pkg_name View the details of a package
rpm -qd pkg_name Query the documentation provided by a package
rpm -qc pkg_name Check the configuration file provided by the installed RPM package
rpm -ql pkg_name See what files a package has installed
rpm -qf filename Check which package a file belongs to
rpm -qR pkg_name Query package dependencies
rpm -ivh xxx.rpm Install the RPM package
rpm -ivh –test xxx.rpm Test the installation of RPM packages
rpm -ivh –nodeps xxx.rpm Ignore dependencies when installing RPM packages
rpm -e xxx Uninstall package
rpm -Fvh pkg_name Upgrade RPM packages that have been installed
rpm -Uvh pkg_name Upgrade RPM packages (if not installed)
rpm -V pkg_name RPM package details verification
. .

YUM package management command

Common commands role
yum repolist enabled Displays available source repositories
yum search pkg_name Searching for software packages
yum install pkg_name Download and install the software package
yum install pkg_name Download, not install
yum list Displays all packages
yum list installed View the current system installation package
yum list updates View the list of packages that can be updated
yum check-update View upgradable software packages
yum update Update all software packages
yum update pkg_name Upgrading a specified software package
yum deplist pkg_name Lists package dependencies
yum remove pkg_name Deleting a Software Package
yum clean all Clear the cache
yum clean packages Clear the cached software package
yum clean headers Clear cached headers
. .

APT Software Tools

Common commands role
apt-cache search pkg_name Search package
apt-cache show pkg_name Get overview information for packages
apt-get install pkg_namee Install or upgrade software packages
apt-get purge pkg_name Uninstalling software (including configuration)
apt-get remove pkg_name Uninstalling software (excluding configuration)
apt-get update Update the package index
apt-get upgrade Update the installed software package
apt-get clean Clear the cache
. .