A summary of hard-core high-frequency Linux commands (summary sharing)

WBOY
Release: 2021-12-27 19:21:19
forward
1700 people have browsed it

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.

A summary of hard-core high-frequency Linux commands (summary sharing)

Shut down/restart/log off

##Common commandsFunctionshutdown -h nowShut down immediatelyshutdown -h 10Shut down after 10 minutes shutdown -h 11:0011:00 shutdownshutdown -h 10 Shutdown at scheduled time (after 10 minutes)shutdown -cCancel shutdown at specified timeshutdown -r nowRestartshutdown -r 10Restart after 10 minutesshutdown -r 11:00 Scheduled restartrebootRestartinit 6Restartinit 0Shut down immediatelytelinit 0Shut downpoweroffShut down immediatelyhaltShut downsyncSynchronize buff data to disklogoutExit 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 commandsFunction##uname -auname -runame -marchhostnamewhowho am iwhoamicat /proc/versioncat /proc/cpuinfocat /proc/interruptscat /proc/loadavguptimeenvlsusb -tvlspci -tvlsmodgrep MemTotal /proc/meminfogrep MemFree / proc/meminfofree -mdatecal 2021 topvmstat 1 20iostatsar -u 1 10sar -d 1 10

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...

View the kernel /OS/CPU Information
View kernel version
View processor architecture
View processor architecture
View computer name
Display the user who is currently logged in to the system
Display the user who is logged in Name
Display current user name
View linux version Information
View CPU information
View interrupts
View system load
View system operation Time, number of users, load
View system environment variables
View system USB device information
View system PCI device information
View loaded system modules
View total memory
Check the amount of free memory
Check the memory usage and swap area usage
Display system date and time
Display 2021 calendar
Dynamic display of cpu/memory/process, etc.
Collect system status every 1 second, 20 times
Check io read and write/cpu usage
Query cpu Usage (once per second, 10 times in total)
Query disk performance
##fdisk -lView all disk partitionsswapon -sView all swap partitionsdf -hView disk usage and mount pointsdf -hlCheck the remaining disk spacedu -sh /dirCheck the size of the specified directoryDisplay file and directory sizes from high to lowmount /dev/hda2 /mnt/hda2Mount hda2 disk##mount -t ntfs /dev/sdc1 /mnt/usbhd1mount -o loop xxx.iso /mnt/cdrommount /dev/sda1 /mnt/usbdisk##umount -v /dev/sda1Uninstall by device nameumount -v /mnt/mymntUninstall by mount pointfuser -km /mnt/hda1Force uninstall (use with caution)##Users and user groups
Commonly used commands Function
du -sk * | sort -rn
Specify the file system type to mount (such as ntfs)
Mount iso file
Mount usb disk/flash device

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 commandsFunction##useradd codesheep Create useruserdel -r codesheepDelete userusermod -g group_name user_nameModify User's groupusermod -aG group_name user_nameAdd user to groupusermod -s /bin/ksh -d /home/codepig –g dev codesheepModify the login shell, home directory and user group of user codesheepgroups testView test The group the user belongs togroupadd group_nameCreate user groupgroupdel group_nameDelete user group groupmod -n new_name old_nameRename user groupsu - user_nameFull switch Go to a user environmentpasswdChange the passwordpasswd codesheepModify the password of a user wView active usersid codesheepView specified user informationlastView user login logcrontab -lView the current user’s scheduled taskscut -d: -f1 /etc/passwdView all users in the systemcut -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.

##netstat -antpView all established connectionsnetstat -lutpView TCP/UDP status informationifup eth0Enable eth0 network device##ifdown eth0iptables -L##ifconfig eth0 192.168.1.1 netmask 255.255.255.0Configure ip addressdhclient eth0Enable eth0 in dhcp moderoute add -net 0/0 gw Gateway_IPConfigure the default gatewayroute add -net 192.168.0.0 netmask 255.255.0.0 gw 192.168.1.1Configure static route to reach network '192.168.0.0/16'route del 0/0 gw Gateway_IPDelete static routehostnameView host namehost www.codesheep.cnResolve host namenslookup www.codesheep.cnQuery DNS records to see if domain name resolution is normalps -efView all processesps -ef | grep codesheepkill -s nameKill the process with the specified namekill -s pid Kill the process with the specified pidtopDisplay process status in real timevmstat 1 20Collect system status every 1 second, 20 timesiostatView io read and write/cpu usagesar -u 1 10Query cpu usage (once per second, 10 times in total) sar -d 1 10Query disk performanceCommon system service commands
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
Disable eth0 network device
View iptables rules
Filter out the process you need

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 --listView a service##service start Start a serviceservice stopTerminate a serviceservice restartRestart a servicesystemctl status View a servicesystemctl start Start a servicesystemctl stop Terminate a servicesystemctl restart Restart a servicesystemctl enable < Service name>Turn on self-startsystemctl 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.

List system services service status
##cd …Return to the upper directorycd …/ …Go back two levels to the directorycdEnter the personal home directorycd -Go back to the directory of the previous steppwdDisplay the current pathlsView file directory listls -FView the contents of the directory (show whether it is a file or directory)ls - lView detailed list of files and directoriesls -aView hidden filesls -lhshow permissionsls -lSrmoretreeView the tree structure of files and directories##mkdir mkdir dir1 dir2mkdir -p /tmp/dir1/dir2rm -f file1rmdir dir1rm -rf dir1rm -rf dir1 dir2mv old_dir new_dircp file1 file2cp dir/* .cp -a dir1 dir2cp -a /tmp/dir1 .ln -s file1 link1ln file1 lnk1find / -name file1find / - user user1find /dir -name *.binlocate Keywordslocate *.mp4whereis haltwhich haltchmod ugo rwx dir1chmod go-rwx dir1chown user1 file1chown -R user1 dir1chgrp group1 file1chown user1:group1 file1

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
cd Enter a directory
Create directory
Create two directories at the same time
Create a directory tree
Delete the 'file1' file
Delete the 'dir1' directory
Delete the 'dir1' directory and its contents
Delete both at the same time Directory and its contents
Rename/Move directory
Copy files
Copy all files in a directory to the current directory
Copy directory
Copy a directory to the current directory
Create a soft link pointing to the file/directory
Create a soft link pointing to the file/ Physical link to the directory
Search for files/directories starting from the following directory
Search the files/directory of user user1
Search for .bin in the directory/dir Files with suffix
Quickly locate files
Find Files ending in .mp4
Display the path of a binary file/executable file
Find binary files in the system directory
Set the directory owner (u), group (g) and others (o) read (r) write (w) execute (x) permissions
Remove group (g) with others (o) Read, write and execute permissions on the directory
Change the owner attribute of the file
Change the owner attribute of the directory
Change the file group
Change the owner and group of the file
##sed - e 's/s1//g' hello.txtDelete only the word s1 from the document and keep all the rest##sed -n '1,5p;5q ' hello.txtsed -n '5p;5q' hello.txtpaste file1 file2paste -d ' ' file1 file2sort file1 file2sort file1 file2##sort file1 file2uniq -usort file1 file2uniq -dcomm -1 file1 file2Compare the contents of the two files (remove The contents of 'file1')comm -2 file1 file2Compare the contents of the two files (remove the contents of 'file2')comm -3 file1 file2Compare the contents of the two files (removing the common parts of the two files)Package Decompression
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
View the content from the first line to the fifth line
View Line 5
Merge the contents of two files or two columns
Merge the contents of two files or two columns, use " " to distinguish
Sort the contents of the two files
uniq

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 commandsFunctionzip xxx.zip file Compress to zip packageCompress multiple file directories into zip packageUnzip the zip package##tar -cvf xxx.tar fileCreate uncompressed tar Packagetar -cvf xxx.tar file1 file2 dir1tar multiple file directoriestar - tf xxx.tarView the contents of the tar packagetar -xvf xxx.tarExtract the tar packagetar -xvf xxx.tar -C /dirExtract the tar package to the specified directorytar -cvfj xxx.tar.bz2 dirCreate bz2 compressed package##tar -zxvf xxx.tar.gzDecompress gzip compressed packagebunzip2 xxx.bz2Decompress bz2 compressed package##bzip2 filenamegunzip xxx.gzgzip filenamegzip -9 filename

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

##zip -r xxx.zip file1 file2 dir1
unzip xxx.zip
##tar -jxvf xxx.tar.bz2 Decompress bz2 compressed package
tar -cvfz xxx.tar.gz dir Create gzip compressed package
Compressed file
Decompress the gzip compressed package
Compressed file
Maximum compression
##rpm -q --whatrequires xxx Display which package the xxx function depends onrpm -q --changelog xxxDisplay the change record of the xxx packagerpm -qi pkg_nameView the detailed information of a packagerpm -qd pkg_nameQuery the location of a package Provided documentationrpm -qc pkg_nameView the configuration file provided by the installed rpm packagerpm -ql pkg_name Check which files are installed in a packagerpm -qf filenameCheck which package a file belongs torpm -qR pkg_nameQuery package dependenciesrpm -ivh xxx.rpmInstall rpm packagerpm -ivh --test xxx.rpmTest installation rpm packagerpm -ivh --nodeps xxx.rpmIgnore dependencies when installing rpm packagerpm -e xxxUninstall package##rpm - Fvh pkg_namerpm -Uvh pkg_namerpm -V pkg_name
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
Upgrade the rpm package that has been installed
Upgrade the rpm package (will install it if not installed)
RPM package details verification
yum package management command

Common commands##yum repolist enabledDisplay Available source repositoriesyum search pkg_nameSearch software packageyum install pkg_nameDownload And install the software packageyum install --downloadonly pkg_nameOnly download but not installyum listDisplay all packagesyum list installedView the current system installed packagesyum list updatesView the list of packages that can be updatedyum check-updateView the package packages that can be upgradedUpdate all software packagesUpgrade the specified software packageList package dependenciesRemove packageClear cacheClear cached packages##yum clean headersClear cached headersdpkg package management command
Function
## yum update
yum update pkg_name
yum deplist pkg_name
yum remove pkg_name
yum clean all
yum clean packages

Commonly used Command

FunctionList the contents of the deb package##dpkg -r pkg_nameRemove deb packagedpkg -P pkg_nameRemove the deb package (without retaining the configuration)dpkg -lView the deb packages installed in the systemdpkg -l pkg_nameDisplay the general information of the packagedpkg -L pkg_nameView the files installed by the deb packagedpkg -s pkg_nameView the detailed information of the packagedpkg –unpack xxx.debUnpack the contents of the deb packageapt software tool
##dpkg -c xxx.deb
dpkg -i xxx.deb Install/update deb package
Common commands

Function

apt-cache search pkg_nameSearch packageapt-cache show pkg_nameGet overview information of the packageapt-get install pkg_nameInstall/ Upgrade software packageapt-get purge pkg_nameUninstall software (including configuration)apt-get remove pkg_nameUninstall software (excluding configuration)apt-get updateUpdate package index information apt-get upgradeUpdate installed packagesapt-get cleanClear cacheLinux Video Tutorial
Related recommendations: ""

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!

Related labels:
source:csdn.net
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template