banner
LegalGeek

LegalGeek

搞产品的法律人

Linux Common Command Manual

Summary: Organizing commonly used Linux commands, once organized, looks very comfortable and is easy to remember.

Shutdown/Reboot/Logout#

Common CommandFunction
shutdown -h nowShut down immediately
shutdown -h 10Shut down in 10 minutes
shutdown -h 11:00Shut down at 11:00
shutdown -h +10Schedule shutdown (in 10 minutes)
shutdown -cCancel scheduled shutdown
shutdown -r nowReboot
shutdown -r 10Reboot in 10 minutes
shutdown -r 11:00Scheduled reboot
rebootReboot
init 6Reboot
init 0Shut down immediately
telinit 0Shut down
poweroffShut down immediately
haltShut down
syncSynchronize buffer data to disk
logoutLogout from Shell

System Information and Performance Monitoring#

Common CommandFunction
uname -aView kernel/OS/CPU information
uname -rView kernel version
uname -mView processor architecture
archView processor architecture
hostnameView computer name
whoDisplay currently logged-in users
who am iDisplay username at login
whoamiDisplay current username
cat /proc/versionView Linux version information
cat /proc/cpuinfoView CPU information
cat /proc/interruptsView interrupts
cat /proc/loadavgView system load
uptimeView system uptime, user count, load
envView system environment variables
lsusb -tvView system USB device information
lspci -tvView system PCI device information
lsmodView loaded system modules
grep MemTotal /proc/meminfoView total memory
grep MemFree /proc/meminfoView free memory
free -mView memory usage and swap usage
dateDisplay system date and time
cal 2021Display 2021 calendar
topDynamically display CPU/memory/process status
vmstat 1 20Sample system status every 1 second, 20 times
iostatView IO read/write/CPU usage
sar -d 1 10Query disk performance

Disk and Partition#

Common CommandFunction
fdisk -lView all disk partitions
swapon -sView all swap partitions
df -hView disk usage and mount points
df -hlSame as above
du -sh /dirView the size of a specific directory
du -sk *sort -rn
mount /dev/hda2 /mnt/hda2Mount hda2 disk
mount -t ntfs /dev/sdc1 /mnt/usbhd1Mount with specified filesystem type (e.g., ntfs)
mount -o loop xxx.iso /mnt/cdromMount ISO file
umount -v /dev/sda1Unmount by device name
umount -v /mnt/mymntUnmount by mount point
fuser -km /mnt/hda1Force unmount (use with caution)

User and User Group#

Common CommandFunction
useradd legalgeekCreate user
userdel -r legalgeekDelete user
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 legalgeekModify legalgeek's login shell, home directory, and group
groups testView groups of test user
groupadd group_nameCreate user group
groupdel group_nameDelete user group
groupmod -n new_name old_nameRename user group
su - user_nameSwitch to user_name user
passwdChange password
passwd legalgeekChange password for a specific user
wView active users
id legalgeekView information for specified user legalgeek
lastView user login logs
crontab -lView current user's scheduled tasks
cut -d: -f1 /etc/passwdView all system users
cut -d: -f1 /etc/groupView all system groups

Network and Process Management#

Common CommandFunction
ifconfigView network interface properties
ifconfig eth0View configuration of a specific network card
route -nView routing table
netstat -lntpView all listening ports
netstat -antpView established TCP 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 default gateway
route 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 route
hostnameView hostname
host www.baidu.comResolve hostname
nslookup www.baidu.comQuery DNS records, check domain resolution status
ps -efView all processes
ps -efgrep legalgeek
kill -s nameKill process with specified name
kill -s pidKill process with specified pid
topDisplay process status in real-time
vmstat 1 20Sample system status every 1 second, 20 times
iostatiostat
sar -u 1 10Query CPU usage (once every second, 10 times)
sar -d 1 10Query disk performance

Common System Service Commands#

Common CommandFunction
chkconfig --listList system services
service <service_name> statusView a specific service
service <service_name> startStart a specific service
service <service_name> stopStop a specific service
service <service_name> restartRestart a specific service
systemctl status <service_name>View a specific service
systemctl start <service_name>Start a specific service
systemctl stop <service_name>Stop a specific service
systemctl restart <service_name>Restart a specific service
systemctl enable <service_name>Disable auto-start
systemctl disable <service_name>Disable auto-start

File and Directory Operations#

Common CommandFunction
cd <directory_name>Enter a specific directory
cd ..Go to the parent directory
cd ../..Go back two levels in the directory
cdEnter the home directory
cd -Go back to the previous directory
pwdDisplay current path
lsView file directory list
ls -FView contents of the directory (show whether it's a file or directory)
ls -lView detailed list of files and directories
ls -aView hidden files
ls -lhView detailed list of files and directories (enhanced readability of file sizes)
ls -lSrView file and directory list (sorted by file size in ascending order)
treeView tree structure of files and directories
mkdir <directory_name>Create directory
mkdir dir1 dir2Create two directories at once
mkdir -p /tmp/dir1/dir2Create directory tree
rm -f file1Delete 'file1' file
rmdir dir1Delete 'dir1' directory
rm -rf dir1Delete 'dir1' directory and its contents
rm -rf dir1 dir2Delete two directories and their contents at once
mv old_dir new_dirRename/move directory
cp file1 file2Copy file
cp dir/* .Copy all files from 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 symbolic link to a file/directory
ln file1 lnk1Create a hard link to a file/directory
find / -name file1Search for file/directory starting from the root directory
find / -user user1Search for files/directories owned by user1
find /dir -name *.binSearch for files with .bin suffix in directory /dir
locate Quickly locate files
locate *.mp4Find files ending with .mp4
whereis Show the path of a binary/executable file
which Find a binary file in system directories
chmod ugo+rwx dir1Set read (r), write (w), and execute (x) permissions for owner (u), group (g), and others (o) on directory
chmod go-rwx dir1Remove read, write, and execute permissions for group (g) and others (o) on directory
chown user1 file1Change file owner
chown -R user1 dir1Change directory owner
chgrp group1 file1Change file group
chown user1 file1Change file owner and group

File Viewing and Processing#

Common CommandFunction
cat file1View file content
cat -n file1View content and show line numbers
tac file1View file content starting from the last line
more file1more file1
less file1Similar to 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/msgReal-time view of content added to the file
grep legalgeek hello.txtSearch for the keyword legalgeek in hello.txt
grep ^sheep hello.txtSearch for content starting with sheep in hello.txt
grep [0-9] hello.txtSelect all lines in hello.txt containing numbers
sed 's/s1/s2/g' hello.txtReplace s1 with s2 in hello.txt
sed '/^$/d' hello.txtDelete all empty lines from hello.txt
sed '/ *#/d; /^$/d' hello.txtDelete all comments and empty lines from hello.txt
sed -e '1d' hello.txtExclude the first line from hello.txt
sed -n '/s1/p' hello.txtView lines containing the keyword "s1"
sed -e 's/ *$//' hello.txtRemove trailing whitespace from each line
sed -e 's/s1//g' hello.txtRemove only the word s1 from the document and keep the rest
sed -n '1,5p;5q' hello.txtView content from the first line to the 5th line
sed -n '5p;5q' hello.txtView the 5th line
paste file1 file2Merge content of two files or columns
paste -d '+' file1 file2Merge content of two files or columns, separated by "+"
sort file1 file2Sort content of two files
comm -1 file1 file2Compare content of two files (remove content in 'file1')
comm -2 file1 file2Compare content of two files (remove content in 'file2')
comm -3 file1 file2Compare content of two files (remove common parts)

Packaging and Unpacking#

Common CommandFunction
zip xxx.zip fileCompress to zip package
zip -r xxx.zip file1 file2 dir1Compress multiple files and directories into zip package
unzip xxx.zipUnzip zip package
tar -cvf xxx.tar fileCreate uncompressed tar package
tar -cvf xxx.tar file1 file2 dir1Create tar package from multiple files and directories
tar -tf xxx.tarView contents of tar package
tar -xvf xxx.tarUnzip tar package
tar -xvf xxx.tar -C /dirUnzip tar package to specified directory
tar -cvfj xxx.tar.bz2 dirCreate bz2 compressed package
tar -jxvf xxx.tar.bz2Unzip bz2 compressed package
tar -cvfz xxx.tar.gz dirCreate gzip compressed package
tar -zxvf xxx.tar.gzUnzip gzip compressed package
bunzip2 xxx.bz2Unzip bz2 compressed package
bzip2 filenameCompress file
gunzip xxx.gzUnzip gzip compressed package
gzip filenameCompress file
gzip -9 filenameMaximum compression

RPM Package Management Commands#

Common CommandFunction
rpm -qaView installed rpm packages
rpm -q pkg_nameQuery a specific rpm package
rpm -q --whatprovides xxxShow which package provides xxx functionality
rpm -q --whatrequires xxxShow which package depends on xxx functionality
rpm -q --changelog xxxShow changelog of xxx package
rpm -qi pkg_nameView detailed information of a package
rpm -qd pkg_nameQuery documentation provided by a package
rpm -qc pkg_nameView configuration files provided by installed rpm package
rpm -ql pkg_nameView files installed by a package
rpm -qf filenameView which package a file belongs to
rpm -qR pkg_nameQuery package dependencies
rpm -ivh xxx.rpmInstall rpm package
rpm -ivh --test xxx.rpmTest install rpm package
rpm -ivh --nodeps xxx.rpmInstall rpm package ignoring dependencies
rpm -e xxxUninstall package
rpm -Fvh pkg_nameUpgrade an already installed rpm package
rpm -Uvh pkg_nameUpgrade rpm package (install if not installed)
rpm -V pkg_nameVerify detailed information of RPM package

YUM Package Management Commands#

Common CommandFunction
yum repolist enabledShow available source repositories
yum search pkg_nameSearch for software package
yum install pkg_nameDownload and install software package
yum install --downloadonly pkg_nameDownload without installing
yum listShow all packages
yum list installedView currently installed packages
yum list updatesView updatable package list
yum check-updateView upgradable software packages
yum updateUpdate all software packages
yum update pkg_nameUpgrade specified software package
yum deplist pkg_nameList package dependencies
yum remove pkg_nameRemove software package
yum clean allClear cache
yum clean packagesClear cached packages
yum clean headersClear cached headers

DPKG Package Management Commands#

Common CommandFunction
dpkg -c xxx.debList contents of deb package
dpkg -i xxx.debInstall/upgrade deb package
dpkg -r pkg_nameRemove deb package
dpkg -P pkg_nameRemove deb package (without configuration)
dpkg -lView installed deb packages
dpkg -l pkg_nameShow general information of package
dpkg -L pkg_nameView files installed by deb package
dpkg -s pkg_nameView detailed information of package
dpkg –unpack xxx.debUnpack contents of deb package

APT Software Tools#

Common CommandFunction
apt-cache search pkg_nameSearch for software package
apt-cache show pkg_nameGet overview information of package
apt-get install pkg_nameInstall/upgrade software package
apt-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 software packages
apt-get cleanClean cache
Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.