Before the speech

I remember not long ago I shared with you some useful and efficient online tools and websites in my daily work, study, development, writing and video making, and exported all my browser favorites and bookmarks offline files to you.

The background feedback of many friends is good, saying that after the bookmark is imported, many tools are really good to use, mainly saving a lot of time to find resources and organize.

Today continue to share, recently spent a lot of time to the usual development process of some common Linux system commands to do a big arrangement, form a commonly used high-frequency Linux quick check memo. With it, also afraid of Linux operating system common operations and commands can not remember?

Then serve the food directly.

Note: This article is on GitHub
https://github.com/rd2coding/Road2CodingIt has been included. I have organized it
6 programming direction (post) self-study route + knowledge points combing,
The interview examination site,
My resume,
Several hardcore PDF notes, as well as
My life as a programmer.


Shutdown/reboot/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 Shutdown at predetermined time (after 10 minutes)
shutdown -c Cancels 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 Log out of Shell

Note: What’s the difference between shutdown, poweroff, halt, or init 0? If you are interested in this, you can understand it by yourself. They are different.


System information and performance view

Command here actually use at ordinary times is very much, because once the system or background services in addition to the problem, we should reach out to look at, often include a lot of system information, such as: system version, the kernel version, processor architecture, computer name, environment variables, user situation, load, memory usage, disk information, process, Internet connection…

Common commands role
uname -a View kernel /OS/CPU information
uname -r View kernel version
uname -m View processor architecture
arch View processor architecture
hostname View computer name
who Displays the user currently logged in to the system
who am i Displays the user name when logging in
whoami Displays the current user name
cat /proc/version View Linux version information
cat /proc/cpuinfo View CPU information
cat /proc/interrupts View the interrupt
cat /proc/loadavg View the system load
uptime Check the system running time, number of users, load
env Look at the environment variables for your system
lsusb -tv View system USB device information
lspci -tv View system PCI device information
lsmod View the loaded system modules
grep MemTotal /proc/meminfo View total memory
grep MemFree /proc/meminfo View the amount of free memory
free -m Look at the memory usage and swap usage
date Displays system date and time
cal 2021 Displays the calendar table of 2021
top Dynamic display of CPU/memory/process, etc
vmstat 1 20 Collect system status once every 1 second, 20 times
iostat View IO read/write/CPU usage
sar -u 1 10 Query CPU usage (10 times, once per second)
sar -d 1 10 Query disk performance

Disks and partitions

These are some of the commonly used commands, and daily use is inside the Windows we little mouse, the graphical interface can view, but we should master in Linux in order to view, such as: all kinds of partition information view, disk usage, and the size of the files and directories, all kinds of mount and unload…

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 Check the disk space left
du -sh /dir View the specified directory size
`du -sk * sort -rn` Displays file and directory sizes from high to low
mount /dev/hda2 /mnt/hda2 Mount the hda2 plate
mount -t ntfs /dev/sdc1 /mnt/usbhd1 Mount specified file system type (such as NTFS)
mount -o loop xxx.iso /mnt/cdrom Mount the ISO file
mount /dev/sda1 /mnt/usbdisk Mount the usb drive/flash device
umount -v /dev/sda1 Unmount by device name
umount -v /mnt/mymnt Unmount through the hardpoint
fuser -km /mnt/hda1 Forced Uninstall (used with caution)

Users and user groups

Linux user group and the user itself is also a very important concept, this part of the command is mainly about: user CRUD, user group CURD, and then also includes the search user, switch user, change password, check the user login log…

Common commands role
useradd codesheep Create a user
userdel -r codesheep Delete user
usermod -g group_name user_name Modify the user’s 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 for user codesheep
groups test View the group that the test user belongs to
groupadd group_name Create a User Group
groupdel group_name Delete user group
groupmod -n new_name old_name Rename the user group
su – user_name Complete switch to a user environment
passwd Change password
passwd codesheep Modify the password for a user
w View active users
id codesheep View the specified user information
last View the user login log
crontab -l View the current user’s scheduled tasks
cut -d: -f1 /etc/passwd View all users of the system
cut -d: -f1 /etc/group View all groups on the system

Network and process management

As a backend development, these commands are often used, such as: view the network, view the connection, view the port service, configure the network card/firewall/routing table /DNS, view and filter the process, collect the system status, and some system performance monitoring and troubleshooting commands… And so on. These commands come in handy when back-end developers connect to corporate servers to troubleshoot problems, and are used frequently.

Common commands role
ifconfig View the network interface properties
ifconfig eth0 View the configuration of a network card
route -n View the routing table
netstat -lntp View all listening ports
netstat -antp View all connections that have been established
netstat -lutp View TCP/UDP status information
ifup eth0 Enable the eth0 network device
ifdown eth0 Disable eth0 network devices
iptables -L Look at the iptables rule
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 Configuring the default gateway
Route Add-net 192.168.0.0 NetMask 255.255.0.0GW 192.168.1.1 Route Add-net 192.168.0.0 NetMask 255.255.0.0GW 192.168.1.1 Configure static routing arrival network ‘192.168.0.0/16’
route del 0/0 gw Gateway_IP Delete static route
hostname View hostname
host www.codesheep.cn Resolve hostname
nslookup www.codesheep.cn Query the DNS records to see if the domain name resolution is working
ps -ef View all processes
`ps -ef grep codesheep` Filter out the processes you need
kill -s name Kill the process with the name specified
kill -s pid Kill specifies the process for the pid
top Display process status in real time
vmstat 1 20 Collect system status once every 1 second, 20 times
iostat View IO read/write/CPU usage
sar -u 1 10 Query CPU usage (10 times, once per second)
sar -d 1 10 Query disk performance

Common system service commands

This type of command usually contact also a lot of, for example, we are in the installation and deployment of a variety of basic programming environment and services are often used, such as the installation of JDK, MySQL database, Redis cache, NGINX server…

Common commands role
chkconfig --list List system services
Service < > status View a service
Service < > start Start a service
Service < name > stop Terminating a service
Service < name > restart Restart a service
Systemctl status < service name > View a service
Systemctl start < service name > Start a service
Systemctl stop < service name > Terminating a service
SystemCTL restart < service name > Restart a service
Systemctl enable < service name > Open self start
Systemctl Disable < service name > Close self start

File and directory operations

These commands are all the basic operations used by Linux system, and are also the most frequently used commands in daily life, about file operation, about directory operation, about the path. For example: a variety of high-frequency operations on files and directories, create, view, find, delete, rename, copy, soft connect, quick location and find… And so on. These are high frequency and practical commands.

Common commands role
CD < directory name > Go to a directory
cd .. Back to higher directory
cd .. /.. Go back up two levels
cd Enter the personal home directory
cd – Go back to the previous step
pwd Show the current path
ls View the list of file directories
ls -F View the contents of the directory (shows file or directory)
ls -l View a detailed list of files and directories
ls -a View Hidden Files
ls -lh Show permissions
ls -lSr more View files/directories by 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 . Copies a directory to the current directory
ln -s file1 link1 Create a soft link to a file/directory
ln file1 lnk1 Create a physical link to a file/directory
find / -name file1 Search for files/directories starting with the following directory
find / -user user1 Search the file/directory for user user1
find /dir -name *.bin Search the directory /dir for files with the.bin suffix
Locate the key word Fast Locating Files
locate *.mp4 Look for files ending in.mp4
whereis halt Displays the path to a binary/executable file
which halt Find binaries in the system directory
chmod ugo+rwx dir1 Sets read (r) write (w) execute (x) permissions for directory owners (u), groups (g), and others (o)
chmod go-rwx dir1 Removes group (G) and others (O) access to read and write to the directory
chown user1 file1 Changes the owner properties of the file
chown -R user1 dir1 Changes the owner property of the directory
chgrp group1 file1 Change file group
chown user1:group1 file1 Change the owners and groups of the file

File view and processing

This part of the command is mainly targeted at the file processing or text processing, for example, we as a programmer, that the operation is the source of the code file, all kinds of fad view, compare, increase, delete, replace, merge… And so on a series of quick operations.

Common commands role
cat file1 View file contents
cat -n file1 View the content and mark the number of lines
cat xxx.txt awk ‘NR%2==1’ View all odd-numbered lines in the file
tac file1 Review the contents of the file backwards 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 what is 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 for something starting with SHEEP in the file hello.txt
grep [0-9] hello.txt Select all lines in the hello.txt file that contain numbers
sed ‘s/s1/s2/g’ hello.txt Replace s1 with s2 in the hello.txt file
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 Look at the rows that contain only the keyword “s1”
sed -e ‘s/ *$//’ hello.txt Delete the last whitespace character on each line
sed -e ‘s/s1//g’ hello.txt Remove only the term S1 from the document and keep 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 Merges the contents of two files or columns
paste -d ‘+’ file1 file2 Merges the contents of two files or columns, separated by a “+”
sort file1 file2 Sort the contents of two files
sort file1 file2 uniq Take out the union (keep only one copy of duplicate rows)
sort file1 file2 uniq -u Delete the intersection, leaving other rows
sort file1 file2 uniq -d Take the intersection
comm -1 file1 file2 Compare the contents of two files (excluding the contents of ‘file1’)
comm -2 file1 file2 Compare the contents of two files (remove the contents of ‘file2’)
comm -3 file1 file2 Compare the contents of two files (excluding the parts common to both files)

Pack and unpack

This part of the content is mainly about the file or directory packaging compression and decompression, involving several compressed package formats and files, this part of the command is usually used very, very frequently.

Common commands role
zip xxx.zip file Compress to a zip package
zip -r xxx.zip file1 file2 dir1 Press 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 + directories
tar -tf xxx.tar View the contents of the tar package
tar -xvf xxx.tar Unpack the tar packages
tar -xvf xxx.tar -C /dir Unzip the tar package to the specified directory
tar -cvfj xxx.tar.bz2 dir Create the BZ2 package
tar -jxvf xxx.tar.bz2 Unzip the BZ2 package
tar -cvfz xxx.tar.gz dir Create a GZIP archive
tar -zxvf xxx.tar.gz Extract the gzip archive
bunzip2 xxx.bz2 Unzip the BZ2 package
bzip2 filename The compressed file
gunzip xxx.gz Extract the gzip archive
gzip filename The compressed file
gzip -9 filename Maximum compression

Then there are some common package manager commands. First of all, you should know what a package manager is.

Let’s just say that without a package manager, just installing software on a Linux system would discourage a lot of users, because a lot of software dependency processing would be annoying. So in a nutshell, we can think of a package manager as a component that provides support for installing, uninstalling, upgrading, and querying software on a Linux system, so it is generally a set of utility commands for user use.

For example, the most widely used package structure is the RPM package manager, which is used by systems such as RedHat and CentOS. The typical commands are RPM and yum. Then there is the DPKG package manager, which is used by systems such as Debon and Ubuntu, with typical commands such as DPKG commands and apt software tools.


RPM package management commands

Common commands role
rpm -qa View the installed RPM packages
rpm -q pkg_name Query an RPM package
rpm -q –whatprovides xxx Show which package provides the XXX functionality
rpm -q –whatrequires xxx Shows which packages the XXX function is dependent on
rpm -q –changelog xxx Displays the change record for the XXX package
rpm -qi pkg_name View the details of a package
rpm -qd pkg_name Query the documents provided by a package
rpm -qc pkg_name View the configuration files provided by the installed RPM package
rpm -ql pkg_name See what files a package has installed
rpm -qf filename To see 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 RPM package installation
rpm -ivh –nodeps xxx.rpm Ignore dependencies when installing the RPM package
rpm -e xxx Uninstall package
rpm -Fvh pkg_name Upgrade to determine the installed RPM package
rpm -Uvh pkg_name Upgrade the RPM package (if not installed)
rpm -V pkg_name RPM package details verification

YUM package management command

Common commands role
yum repolist enabled Displays the available source repositories
yum search pkg_name Search package
yum install pkg_name Download and install the package
yum install –downloadonly pkg_name Download only, not install
yum list Display all packages
yum list installed View the installed packages for the current system
yum list updates View the list of packages that can be updated
yum check-update Look at upgradable packages
yum update Update all packages
yum update pkg_name Upgrade a specified package
yum deplist pkg_name Lists package dependencies
yum remove pkg_name Delete package
yum clean all Clear the cache
yum clean packages Clear the cached package
yum clean headers Clear the cached headers

The DPKG package management command

Common commands role
dpkg -c xxx.deb Lists the contents of the deb package
dpkg -i xxx.deb Install/update the DEB package
dpkg -r pkg_name Remove the deb package
dpkg -P pkg_name Remove the deb package (without preserving the configuration)
dpkg -l Check that the DEB package is installed on your system
dpkg -l pkg_name Displays general information about the package
dpkg -L pkg_name View the files for the deb package installation
dpkg -s pkg_name View package details
DPKG — unpack XXX. Deb Unwrap the contents of the deb package

APT Software Tools

Common commands role
apt-cache search pkg_name Search package
apt-cache show pkg_name Gets the overview information for the package
apt-get install pkg_name Install/upgrade software packages
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 the cache

Offline files

In addition to the above content, the comb also put those high-frequency useful Linux commands to carry out, and make the two forms of offline document, respectively, in PDF format and high-definition image format, PDF convenient computer view, high-definition pictures, convenient use cell phone to see, so it’s okay to kung fu can take it out on your phone Chou Chou, take a look at.

The PDF document looks something like this:

HD images look something like this, a dozen of them, with hundreds of commands:

The document making
https://github.com/rd2coding/Road2CodingIt’s already included.


Remember after

In addition, I recently spent a lot of effort to self-use programming learning resources to do a big reorganization.

They are all pure liver goods. The list is as follows.

The content of making
https://github.com/rd2coding/Road2CodingIt’s already included, and there’s something I’ve compiled
6 major programming direction of self-study route + knowledge points combing,
My resume,
The interview examination site,
Several hardcore PDF notes, as well as
My life as a programmerWelcome to STAR.

The sorting is not easy, welcome support, see you next time!