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 |
iostat | View the I/O read/write/CPU usage |
View the I/O read/write/CPU usage | Query THE CPU usage once every second (10 times) |
sar -d 1 10 | Querying Disk Performance |
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 |
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 codesheep | Create a user |
userdel -r codesheep | 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/codePig -g dev codesheep | Modify the login Shell, home directory, and user group of user codesheep |
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 | su – user_name |
passwd | Change password |
passwd codesheep | Example Change the password of a user |
w | Viewing Active Users |
id codesheep | View information about the specified user codesheep |
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 static route to network ‘192.168.0.0/16’ |
route del 0/0 gw Gateway_IP | Deleting a Static Route |
hostname | Viewing host Names |
host www.baidu.com | Resolving host names |
nslookup www.baidu.com | Query DNS records to check whether domain name resolution is normal |
ps -ef | Viewing All Processes |
ps -ef | grep codesheep | Filter out the processes you need |
kill -s name | Kill Specifies the name of the process |
kill -s pid | Kill Specifies the PID process |
top | Displays process status in real time |
vmstat 1 20 | System status is collected every second for 20 times |
iostat | iostat |
sar -u 1 10 | Query THE CPU usage once every second (10 times) |
sar -d 1 10 | Querying Disk Performance |
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 | Turn off autostart |
Systemctl disable < service name > | Turn off autostart |
File and directory operations
Common commands | role |
---|---|
CD < directory name > | Go to a directory |
cd .. | Back to parent directory |
cd .. /.. | Go back two levels of directory |
cd | Go to your personal home directory |
cd – | Go back to the directory of the previous step |
pwd | Display current path |
ls | View the file directory list |
ls -F | View the contents of a directory (is it a file or a directory?) |
ls -l | View a detailed list of files and directories |
ls -a | View hidden files |
ls -lh | View detailed lists of files and directories (to improve file size readability) |
ls -lSr | View a list of files and directories (in ascending file size) |
tree | View the tree structure of files and directories |
Mkdir < directory name > | Create a directory |
mkdir dir1 dir2 | Create two directories simultaneously |
mkdir -p /tmp/dir1/dir2 | Creating 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 directories and their contents simultaneously |
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 |
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 |
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 | more file1 |
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 codesheep hello.txt | Look for the keyword codesheep in the file hello.txt |
grep ^sheep hello.txt | Look in the file hello.txt for anything that begins with sheep |
grep [0-9] hello.txt | Select all the lines in the hello.txt file that contain numbers |
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 xxx.zip | Unpack the zip package |
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 -cvfj xxx.tar.bz2 dir | Create the BZ2 zip package |
tar -jxvf xxx.tar.bz2 | Decompress the BZ2 package |
tar -cvfz 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 |
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 xxx | 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 –downloadonly pkg_name | Only under load can not be installed |
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 |
DPKG package management command
Common commands | role |
---|---|
dpkg -c xxx.deb | Lists the contents of deb packages |
dpkg -i xxx.deb | Install/update deb packages |
dpkg -r pkg_name | Remove the deb package |
dpkg -P pkg_name | Remove deb package (without retaining configuration) |
dpkg -l | Check the deb package installed in the system |
dpkg -l pkg_name | Displays general information about the package |
dpkg -L pkg_name | View the deb package installation file |
dpkg -s pkg_name | View package details |
DPKG — unpack XXX. Deb | Unpack the contents of the DEB package |
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_name | 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 |