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 commands | effect |
---|---|
shutdown -h now | Shut down now |
shutdown -h 10 | Shut down after 10 minutes |
shutdown -h 11:00 | 11:00 shutdown |
shutdown -h +10 | Shut down at scheduled time (10 minutes later) |
shutdown -c | Cancel the specified time to shut down |
shutdown -r now | Reboot |
shutdown -r 10 | Restart in 10 minutes |
shutdown -r 11:00 | Restart regularly |
reboot | Reboot |
init 6 | Reboot |
init 0 | Shut down immediately |
telinit 0 | Shut down |
poweroff | Shut down immediately |
halt | Shut down |
sync | Synchronize buff data to disk |
logout | Log 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 commands | effect |
---|---|
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 | Display the users currently logged in to the system |
who am i | Display the user name when logging in |
whoami | Display current user name |
cat /proc/version | View linux version information |
cat /proc/cpuinfo | View CPU information |
cat /proc/interrupts | View interrupt |
cat /proc/loadavg | View system load |
uptime | View system running time, number of users, load |
env | View system environment variables |
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 the total amount of memory |
grep MemFree /proc/meminfo | View the amount of free memory |
free -m | View memory usage and swap area usage |
date | Display system date and time |
cal 2021 | Show 2021 calendar |
top | Dynamic display of cpu/memory/process, etc. |
vmstat 1 20 | The system status is collected every 1 second, 20 times |
iostat | View io read/write/cpu usage |
sar -u 1 10 | Query cpu usage (once every 1 second, 10 times in total) |
sar -d 1 10 | Query 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 commands | effect | |
---|---|---|
fdisk -l | View all disk partitions | |
swapon -s | View all swap partitions | |
df -h | View disk usage and mount point | |
df -hl | Check the remaining space on the disk | |
du -sh /dir | View the specified directory size | |
`du -sk * | sort -rn` | Display file and directory sizes in order from high to low |
mount /dev/hda2 /mnt/hda2 | Mount hda2 disk | |
mount -t ntfs /dev/sdc1 /mnt/usbhd1 | Specify the file system type to mount (such as ntfs) | |
mount -o loop xxx.iso /mnt/cdrom | Mount the iso file | |
mount /dev/sda1 /mnt/usbdisk | Mount usb disk/flash device | |
umount -v /dev/sda1 | Uninstall by device name | |
umount -v /mnt/mymnt | Unmount via mount point | |
fuser -km /mnt/hda1 | Force 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 commands | effect |
---|---|
useradd codesheep | Create user |
userdel -r codesheep | delete users |
usermod -g group_name user_name | Modify user's group |
usermod -aG group_name user_name | Add user to 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 | Create user group |
groupdel group_name | Delete user group |
groupmod -n new_name old_name | Rename user group |
su - user_name | Completely switch to a user environment |
passwd | Change password |
passwd codesheep | Modify a user's password |
w | View active users |
id codesheep | View specified user information |
last | View user login logs |
crontab -l | View the scheduled tasks of the current user |
cut -d: -f1 /etc/passwd | View all users of the system |
cut -d: -f1 /etc/group | View 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 commands | effect | |
---|---|---|
ifconfig | View network interface properties | |
ifconfig eth0 | View the configuration of a network card | |
route -n | View routing table | |
netstat -lntp | View all listening ports | |
netstat -antp | View all established connections | |
netstat -lutp | View TCP/UDP status information | |
ifup eth0 | Enable eth0 network device | |
ifdown eth0 | Disable eth0 network device | |
iptables -L | View iptables rules | |
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 | Configure 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 reach the 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 DNS records to check whether the domain name resolution is normal | |
ps -ef | View all processes | |
`ps -ef | grep codesheep` | Filter out the processes you need |
kill -s name | kill the process with the specified name | |
kill -s pid | kill the process of the specified pid | |
top | Real-time display of process status | |
vmstat 1 20 | The system status is collected every 1 second, 20 times | |
iostat | View io read/write/cpu usage | |
sar -u 1 10 | Query cpu usage (once every 1 second, 10 times in total) | |
sar -d 1 10 | Query 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 commands | effect |
---|---|
chkconfig --list | List system services |
service <service name> status | View a service |
service <service name> start | Start a service |
service <service name> stop | Terminate a service |
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> | 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 commands | effect | |
---|---|---|
cd <directory name> | Enter a directory | |
cd .. | Back to the parent directory | |
cd ../.. | Back to the two-level directory | |
cd | Enter personal home directory | |
cd - | Back to the directory where the previous step was located | |
pwd | Show current path | |
ls | View file directory list | |
ls -F | View the contents of the directory (show whether it is a file or a directory) | |
ls -l | View the 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 at the same time | |
mkdir -p /tmp/dir1/dir2 | Create directory tree | |
rm -f file1 | Delete file'file1' | |
rmdir dir1 | Delete the'dir1' directory | |
rm -rf dir1 | Delete the'dir1' directory and its contents | |
rm -rf dir1 dir2 | Delete two directories and their contents at the same time | |
mv old_dir new_dir | Rename/move directory | |
cp file1 file2 | Copy files | |
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 a soft link to the file/directory | |
ln file1 lnk1 | Create a physical link to the file/directory | |
find / -name file1 | Search for files/directories starting from the following directory | |
find / -user user1 | Search files/directories of user user1 | |
find /dir -name *.bin | Search for files with a .bin suffix in the directory /dir | |
locate keywords | Quickly locate files | |
locate *.mp4 | Looking for files ending in .mp4 | |
whereis halt | Display the path of a binary file/executable file | |
which halt | Find the binary file in the system directory | |
chmod ugo+rwx dir1 | Set the read (r) write (w) execution (x) permissions of the owner (u), group (g) and others (o) of the directory | |
chmod go-rwx dir1 | Remove group (g) and others (o) permissions to read and write to the directory | |
chown user1 file1 | Change the owner attribute of the file | |
chown -R user1 dir1 | Change the owner attribute of the directory | |
chgrp group1 file1 | Change file group | |
chown user1:group1 file1 | Change 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 commands | effect | |
---|---|---|
cat file1 | View file content | |
cat -n file1 | View the content and mark the number of lines | |
cat xxx.txt | awk 'NR%2==1' | View all odd lines in the file |
tac file1 | Look back at the contents of the file from the last line | |
more file1 | View the contents of a long file | |
less file1 | Similar to the more command, but allows reverse operation | |
head -2 file1 | View the first two lines of the file | |
tail -2 file1 | View 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 | Find the keyword codesheep in the file hello.txt | |
grep ^sheep hello.txt | Find the content starting with sheep in the file hello.txt | |
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 | Exclude the first line from the file hello.txt | |
sed -n '/s1/p' hello.txt | View rows that only contain the keyword "s1" | |
sed -e 's/ *$//' hello.txt | Delete the last blank character in each line | |
sed -e 's/s1//g' hello.txt | Delete only vocabulary s1 from the document and keep all remaining | |
sed -n '1,5p;5q' hello.txt | View the content from the first row to the fifth row | |
sed -n '5p;5q' hello.txt | View line 5 | |
paste file1 file2 | Combine the contents of two files or two columns | |
paste -d '+' file1 file2 | Combine the contents of two files or two columns, separated by "+" in the middle | |
sort file1 file2 | Sort the contents of two files | |
sort file1 file2 | uniq | Take out the union (only keep one copy of duplicate rows) |
sort file1 file2 | uniq -u | Delete the intersection and leave other rows |
sort file1 file2 | uniq -d | Take intersection |
comm -1 file1 file2 | Compare the contents of two files (remove 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 (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 commands | effect |
---|---|
zip xxx.zip file | Compressed to zip package |
zip -r xxx.zip file1 file2 dir1 | Compress multiple files + directories into a zip package |
unzip xxx.zip | Unzip the zip package |
tar -cvf xxx.tar file | Create a non-compressed tar package |
tar -cvf xxx.tar file1 file2 dir1 | Tar package multiple files + directories |
tar -tf xxx.tar | View the contents of the tar package |
tar -xvf xxx.tar | Unzip the tar package |
tar -xvf xxx.tar -C /dir | Unzip the tar package to the specified directory |
tar -cvfj xxx.tar.bz2 dir | Create bz2 compressed package |
tar -jxvf xxx.tar.bz2 | Unzip the bz2 compressed package |
tar -cvfz xxx.tar.gz dir | Create gzip archive |
tar -zxvf xxx.tar.gz | Unzip the gzip compressed package |
bunzip2 xxx.bz2 | Unzip the bz2 compressed package |
bzip2 filename | Compressed file |
gunzip xxx.gz | Unzip the gzip compressed package |
gzip filename | Compressed file |
gzip -9 filename | Maximum 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 commands | effect |
---|---|
rpm -qa | View installed rpm packages |
rpm -q pkg_name | Query a rpm package |
rpm -q --whatprovides xxx | Show which package provides the xxx function |
rpm -q --whatrequires xxx | Show which package depends on the xxx function |
rpm -q --changelog xxx | Display the change record of 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 | View the configuration file provided by the installed rpm package |
rpm -ql pkg_name | View which files are installed by a package |
rpm -qf filename | 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 install rpm package |
rpm -ivh --nodeps xxx.rpm | Ignore dependencies when installing rpm packages |
rpm -e xxx | Uninstall package |
rpm -Fvh pkg_name | Upgrade to determine the installed rpm package |
rpm -Uvh pkg_name | Upgrade rpm package (if not installed, it will be installed) |
rpm -V pkg_name | RPM package detailed information verification |
yum package management commands
Common commands | effect |
---|---|
yum repolist enabled | Show available source repositories |
yum search pkg_name | Search package |
yum install pkg_name | Download and install the software package |
yum install --downloadonly pkg_name | Only download but not install |
yum list | Show all packages |
yum list installed | View the installed packages of the current system |
yum list updates | View the list of packages that can be updated |
yum check-update | View upgradeable packages |
yum update | Update all packages |
yum update pkg_name | Upgrade the specified software package |
yum deplist pkg_name | List package dependencies |
yum remove pkg_name | Remove package |
yum clean all | clear cache |
yum clean packages | Clear cached packages |
yum clean headers | Clear the cached header |
dpkg package management commands
Common commands | effect |
---|---|
dpkg -c xxx.deb | List the contents of the deb package |
dpkg -i xxx.deb | Install/update deb package |
dpkg -r pkg_name | Remove deb package |
dpkg -P pkg_name | Remove the deb package (do not keep the configuration) |
dpkg -l | View the installed deb package in the system |
dpkg -l pkg_name | Show general information about the package |
dpkg -L pkg_name | View the files installed by the deb package |
dpkg -s pkg_name | View package details |
dpkg –unpack xxx.deb | Unpack the contents of the deb package |
apt software tools
Common commands | effect |
---|---|
apt-cache search pkg_name | Search package |
apt-cache show pkg_name | Get overview information of the package |
apt-get install pkg_name | Install/upgrade packages |
apt-get purge pkg_name | Uninstall the software (including configuration) |
apt-get remove pkg_name | Uninstall the software (not including configuration) |
apt-get update | Update package index information |
apt-get upgrade | Update installed packages |
apt-get clean | Clear 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!
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。