35
头图

Preface

some useful and efficient online tools and websites in daily work, study, development, writing, making videos, etc., and I also added my own browser favorites The bookmark offline files are exported to you .

The feedback from many small partners in the background is pretty good, saying that after the bookmarks are imported, many tools are really easy to use, which saves a lot of time in finding resources and organizing.

I continue to share today. Recently, I spent a lot of time to sort out some of the Linux system commands that are commonly used in the usual development process, and form a common high-frequency Linux quick reference memo. With it, are you afraid that you can't remember the common operations and commands of the Linux operating system?

Let's serve directly next.

Note: This article GitHub https://github.com/rd2coding/Road2Coding has been included, and there are my own 6 programming directions (posts) self-study routes + knowledge points combing , , resume 160d3e02d8f823, hardcore pdf notes , and my programmer life .

Shutdown/restart/logout

Common commandseffect
shutdown -h nowShut down now
shutdown -h 10Shut down after 10 minutes
shutdown -h 11:0011:00 shutdown
shutdown -h +10Shut down at scheduled time (10 minutes later)
shutdown -cCancel the specified time to shut down
shutdown -r nowReboot
shutdown -r 10Restart in 10 minutes
shutdown -r 11:00Restart regularly
rebootReboot
init 6Reboot
init 0Shut down immediately
telinit 0Shut down
poweroffShut down immediately
haltShut down
syncSynchronize buff data to disk
logoutLog out of the login shell
Note: What is the difference between shutdown, poweroff, halt, and init 0 for the same shutdown? If you are interested, you can find out for yourself, they are different.

System information and performance view

The command here is actually used a lot, because once the system or background service has problems, we often have to log on to view it, including a lot of system information, such as: system version, kernel version, processor architecture, computer name, environment Variables, user conditions, load conditions, memory usage, disk information, processes, network connections...
Common commandseffect
uname -aView kernel/OS/CPU information
uname -rView kernel version
uname -mView processor architecture
archView processor architecture
hostnameView computer name
whoDisplay the users currently logged in to the system
who am iDisplay the user name when logging in
whoamiDisplay current user name
cat /proc/versionView linux version information
cat /proc/cpuinfoView CPU information
cat /proc/interruptsView interrupt
cat /proc/loadavgView system load
uptimeView system running time, number of users, load
envView system environment variables
lsusb -tvView system USB device information
lspci -tvView system PCI device information
lsmodView the loaded system modules
grep MemTotal /proc/meminfoView the total amount of memory
grep MemFree /proc/meminfoView the amount of free memory
free -mView memory usage and swap area usage
dateDisplay system date and time
cal 2021Show 2021 calendar
topDynamic display of cpu/memory/process, etc.
vmstat 1 20The system status is collected every 1 second, 20 times
iostatView io read/write/cpu usage
sar -u 1 10Query cpu usage (once every 1 second, 10 times in total)
sar -d 1 10Query disk performance

Disks and partitions

These are some commonly used commands that are closely related to daily use. In Windows, we can view them on the graphical interface with a click of the mouse. However, in Linux, we should be proficient in using commands to view, such as: viewing various partition information, Disk usage, file and directory size, various mounting and unmounting...
Common commandseffect
fdisk -lView all disk partitions
swapon -sView all swap partitions
df -hView disk usage and mount point
df -hlCheck the remaining space on the disk
du -sh /dirView the specified directory size
`du -sk *sort -rn`Display file and directory sizes in order from high to low
mount /dev/hda2 /mnt/hda2Mount hda2 disk
mount -t ntfs /dev/sdc1 /mnt/usbhd1Specify the file system type to mount (such as ntfs)
mount -o loop xxx.iso /mnt/cdromMount the iso file
mount /dev/sda1 /mnt/usbdiskMount usb disk/flash device
umount -v /dev/sda1Uninstall by device name
umount -v /mnt/mymntUnmount via mount point
fuser -km /mnt/hda1Force uninstall (use with caution)

Users and user groups

User groups and users themselves are also a very important concept in the Linux system. This part of the commands is mainly about: user CRUD, user group CURD, and then also include checking users, switching users, changing passwords, checking user login logs...
Common commandseffect
useradd codesheepCreate user
userdel -r codesheepdelete users
usermod -g group_name user_nameModify user's group
usermod -aG group_name user_nameAdd user to group
usermod -s /bin/ksh -d /home/codepig –g dev codesheepModify the login shell, home directory and user group of user codesheep
groups testView the group of the test user
groupadd group_nameCreate user group
groupdel group_nameDelete user group
groupmod -n new_name old_nameRename user group
su - user_nameCompletely switch to a user environment
passwdChange password
passwd codesheepModify a user's password
wView active users
id codesheepView specified user information
lastView user login logs
crontab -lView the scheduled tasks of the current user
cut -d: -f1 /etc/passwdView all users of the system
cut -d: -f1 /etc/groupView all groups in the system

Network and process management

As a back-end development, these commands are usually used with high probability, such as: view network, view connection, view port service, configure network card/firewall/routing table/DNS, view and filter process, collect system status, and Some system performance monitoring and troubleshooting commands... etc. These commands are very useful when the back-end development connects to the company's server to troubleshoot problems, and they are used frequently.
Common commandseffect
ifconfigView network interface properties
ifconfig eth0View the configuration of a network card
route -nView routing table
netstat -lntpView all listening ports
netstat -antpView all established connections
netstat -lutpView TCP/UDP status information
ifup eth0Enable eth0 network device
ifdown eth0Disable eth0 network device
iptables -LView iptables rules
ifconfig eth0 192.168.1.1 netmask 255.255.255.0Configure ip address
dhclient eth0Enable eth0 in dhcp mode
route add -net 0/0 gw Gateway_IPConfigure the default gateway
route add -net 192.168.0.0 netmask 255.255.0.0 gw 192.168.1.1Configure a static route to reach the network '192.168.0.0/16'
route del 0/0 gw Gateway_IPDelete static route
hostnameView hostname
host www.codesheep.cnResolve hostname
nslookup www.codesheep.cnQuery DNS records to check whether the domain name resolution is normal
ps -efView all processes
`ps -efgrep codesheep`Filter out the processes you need
kill -s namekill the process with the specified name
kill -s pidkill the process of the specified pid
topReal-time display of process status
vmstat 1 20The system status is collected every 1 second, 20 times
iostatView io read/write/cpu usage
sar -u 1 10Query cpu usage (once every 1 second, 10 times in total)
sar -d 1 10Query disk performance

Common system service commands

Such commands are usually exposed to many, such as when we install and deploy a variety of basic programming environments and services, such as JDK, MySQL database, redis cache, nginx server...
Common commandseffect
chkconfig --listList system services
service <service name> statusView a service
service <service name> startStart a service
service <service name> stopTerminate a service
service <service name> restartRestart a service
systemctl status <service name>View a service
systemctl start <service name>Start a service
systemctl stop <service name>Terminate a service
systemctl restart <service name>Restart a service
systemctl enable <service name>Turn on self-start
systemctl disable <service name>Turn off self-start

File and directory operations

These commands are all the basic operations used by the Linux system, and they are also some of the most frequently used commands, such as file operations, directory operations, and paths. For example: various high-frequency operations on files and directories, creating, viewing, searching, deleting, renaming, copying, soft linking, fast positioning and searching... etc. They are all high-frequency practical commands.
Common commandseffect
cd <directory name>Enter a directory
cd ..Back to the parent directory
cd ../..Back to the two-level directory
cdEnter personal home directory
cd -Back to the directory where the previous step was located
pwdShow current path
lsView file directory list
ls -FView the contents of the directory (show whether it is a file or a directory)
ls -lView the detailed list of files and directories
ls -aView hidden files
ls -lhShow permissions
ls -lSrmoreView files/directories by size
treeView the tree structure of files and directories
mkdir <directory name>Create a directory
mkdir dir1 dir2Create two directories at the same time
mkdir -p /tmp/dir1/dir2Create directory tree
rm -f file1Delete file'file1'
rmdir dir1Delete the'dir1' directory
rm -rf dir1Delete the'dir1' directory and its contents
rm -rf dir1 dir2Delete two directories and their contents at the same time
mv old_dir new_dirRename/move directory
cp file1 file2Copy files
cp dir/* .Copy all files in a directory to the current directory
cp -a dir1 dir2Copy directory
cp -a /tmp/dir1 .Copy a directory to the current directory
ln -s file1 link1Create a soft link to the file/directory
ln file1 lnk1Create a physical link to the file/directory
find / -name file1Search for files/directories starting from the following directory
find / -user user1Search files/directories of user user1
find /dir -name *.binSearch for files with a .bin suffix in the directory /dir
locate keywordsQuickly locate files
locate *.mp4Looking for files ending in .mp4
whereis haltDisplay the path of a binary file/executable file
which haltFind the binary file in the system directory
chmod ugo+rwx dir1Set the read (r) write (w) execution (x) permissions of the owner (u), group (g) and others (o) of the directory
chmod go-rwx dir1Remove group (g) and others (o) permissions to read and write to the directory
chown user1 file1Change the owner attribute of the file
chown -R user1 dir1Change the owner attribute of the directory
chgrp group1 file1Change file group
chown user1:group1 file1Change owner and group of file

File viewing and processing

This part of the command is mainly related to file processing or text processing. For example, as a programmer, the code source file is the most manipulated. Various fancy viewing, comparison, addition, deletion, replacement, merging... etc. Wait for a series of quick operations.
Common commandseffect
cat file1View file content
cat -n file1View the content and mark the number of lines
cat xxx.txtawk 'NR%2==1'View all odd lines in the file
tac file1Look back at the contents of the file from the last line
more file1View the contents of a long file
less file1Similar to the more command, but allows reverse operation
head -2 file1View the first two lines of the file
tail -2 file1View the last two lines of the file
tail -f /log/msgView the content added to the file in real time
grep codesheep hello.txtFind the keyword codesheep in the file hello.txt
grep ^sheep hello.txtFind the content starting with sheep in the file hello.txt
grep [0-9] hello.txtSelect all lines containing numbers in the hello.txt file
sed 's/s1/s2/g' hello.txtReplace s1 in the hello.txt file with s2
sed '/^$/d' hello.txtRemove all blank lines from the hello.txt file
sed '/ *#/d; /^$/d' hello.txtRemove all comments and blank lines from the hello.txt file
sed -e '1d' hello.txtExclude the first line from the file hello.txt
sed -n '/s1/p' hello.txtView rows that only contain the keyword "s1"
sed -e 's/ *$//' hello.txtDelete the last blank character in each line
sed -e 's/s1//g' hello.txtDelete only vocabulary s1 from the document and keep all remaining
sed -n '1,5p;5q' hello.txtView the content from the first row to the fifth row
sed -n '5p;5q' hello.txtView line 5
paste file1 file2Combine the contents of two files or two columns
paste -d '+' file1 file2Combine the contents of two files or two columns, separated by "+" in the middle
sort file1 file2Sort the contents of two files
sort file1 file2uniqTake out the union (only keep one copy of duplicate rows)
sort file1 file2uniq -uDelete the intersection and leave other rows
sort file1 file2uniq -dTake intersection
comm -1 file1 file2Compare the contents of two files (remove the contents of'file1')
comm -2 file1 file2Compare the contents of two files (remove the contents of'file2')
comm -3 file1 file2Compare the contents of two files (remove the common part of the two files)

Pack and unzip

This part of the content is mainly about the packaging, compression and decompression of files or directories. It involves several compressed package formats and files. This part of the command is usually used very, very frequently.
Common commandseffect
zip xxx.zip fileCompressed to zip package
zip -r xxx.zip file1 file2 dir1Compress multiple files + directories into a zip package
unzip xxx.zipUnzip the zip package
tar -cvf xxx.tar fileCreate a non-compressed tar package
tar -cvf xxx.tar file1 file2 dir1Tar package multiple files + directories
tar -tf xxx.tarView the contents of the tar package
tar -xvf xxx.tarUnzip the tar package
tar -xvf xxx.tar -C /dirUnzip the tar package to the specified directory
tar -cvfj xxx.tar.bz2 dirCreate bz2 compressed package
tar -jxvf xxx.tar.bz2Unzip the bz2 compressed package
tar -cvfz xxx.tar.gz dirCreate gzip archive
tar -zxvf xxx.tar.gzUnzip the gzip compressed package
bunzip2 xxx.bz2Unzip the bz2 compressed package
bzip2 filenameCompressed file
gunzip xxx.gzUnzip the gzip compressed package
gzip filenameCompressed file
gzip -9 filenameMaximum compression

Then there 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 only the software installation on the Linux system. I am afraid that many users will be dissuaded, because a lot of software dependence processing will make people crazy. So in simple terms, we can understand the package manager as a component used to provide support for software installation, uninstallation, upgrade, and query on Linux systems, so for users, it is generally a set of tool commands.

We usually use the most widely used, for example, Red Hat’s package structure RPM package manager, which is used in systems such as RedHat, CentOS, etc. The typical commands are rpm commands, yum commands; then there are DPKG package managers, such as Debain, Ubuntu and other systems. Both are used, typical commands such as dpkg command and apt software tool.


rpm package management commands

Common commandseffect
rpm -qaView installed rpm packages
rpm -q pkg_nameQuery a rpm package
rpm -q --whatprovides xxxShow which package provides the xxx function
rpm -q --whatrequires xxxShow which package depends on the xxx function
rpm -q --changelog xxxDisplay the change record of xxx package
rpm -qi pkg_nameView the details of a package
rpm -qd pkg_nameQuery the documentation provided by a package
rpm -qc pkg_nameView the configuration file provided by the installed rpm package
rpm -ql pkg_nameView which files are installed by a package
rpm -qf filenameSee which package a file belongs to
rpm -qR pkg_nameQuery package dependencies
rpm -ivh xxx.rpmInstall the rpm package
rpm -ivh --test xxx.rpmTest install rpm package
rpm -ivh --nodeps xxx.rpmIgnore dependencies when installing rpm packages
rpm -e xxxUninstall package
rpm -Fvh pkg_nameUpgrade to determine the installed rpm package
rpm -Uvh pkg_nameUpgrade rpm package (if not installed, it will be installed)
rpm -V pkg_nameRPM package detailed information verification

yum package management commands

Common commandseffect
yum repolist enabledShow available source repositories
yum search pkg_nameSearch package
yum install pkg_nameDownload and install the software package
yum install --downloadonly pkg_nameOnly download but not install
yum listShow all packages
yum list installedView the installed packages of the current system
yum list updatesView the list of packages that can be updated
yum check-updateView upgradeable packages
yum updateUpdate all packages
yum update pkg_nameUpgrade the specified software package
yum deplist pkg_nameList package dependencies
yum remove pkg_nameRemove package
yum clean allclear cache
yum clean packagesClear cached packages
yum clean headersClear the cached header

dpkg package management commands

Common commandseffect
dpkg -c xxx.debList the contents of the deb package
dpkg -i xxx.debInstall/update deb package
dpkg -r pkg_nameRemove deb package
dpkg -P pkg_nameRemove the deb package (do not keep the configuration)
dpkg -lView the installed deb package in the system
dpkg -l pkg_nameShow general information about the package
dpkg -L pkg_nameView the files installed by the deb package
dpkg -s pkg_nameView package details
dpkg –unpack xxx.debUnpack the contents of the deb package

apt software tools

Common commandseffect
apt-cache search pkg_nameSearch package
apt-cache show pkg_nameGet overview information of the package
apt-get install pkg_nameInstall/upgrade packages
apt-get purge pkg_nameUninstall the software (including configuration)
apt-get remove pkg_nameUninstall the software (not including configuration)
apt-get updateUpdate package index information
apt-get upgradeUpdate installed packages
apt-get cleanClear cache

Offline documents

In addition to the above content, this review also brought out those high-frequency and practical Linux commands, and made two forms of offline documents, which are PDF format and high-definition picture format. PDF is convenient for computer viewing, and high-definition pictures are convenient. Use your mobile phone to view it, so you can take out all the effort you need to take a look at it on your mobile phone.

The PDF document is roughly like this:

The high-definition pictures are almost like this, there are a dozen of them, and they contain hundreds of commands:

The document GitHub https://github.com/rd2coding/Road2Coding has been included.

postscript

In addition, I have recently spent a lot of effort to organize the programming learning resources for my own use.

They are all pure liver products, the catalog is as follows.

The content GitHub https://github.com/rd2coding/Road2Coding already included, there is also my finishing self-line six directions + programming knowledge large comb , my resume , interview test sites , several hardcore pdf notes , and My Programmer's Life , welcome star.

It is not easy to organize, welcome support, see you next time!


CodeSheep
3.4k 声望7.7k 粉丝