Super detailed Linux common command set

Introduction to Linux system

Linux, fully known as GNU/Linux, is a Unix like operating system that is free to use and spread. At the same time, it is also a multi-user, multitasking, multithreading and multi CPU operating system based on POSIX and Unix.

With the development of the Internet, Linux has been supported by software enthusiasts, organizations and companies all over the world. In addition to maintaining a strong development momentum in the server, it has made great progress in personal computers and embedded systems. Users can not only intuitively obtain the implementation mechanism of the operating system, but also modify and improve Linux according to their own needs to make it meet the needs of users to the greatest extent.

Linux not only has stable system performance, but also is open source software. Its core firewall components have high performance and simple configuration, which ensures the security of the system. In many enterprise networks, in order to pursue speed and security, Linux is not only used as a server by network operation and maintenance personnel, but also as a network firewall, which is also a highlight of Linux.

Linux has the characteristics of open source, no copyright and many users in the technical community. Open source allows users to cut freely, with high flexibility, powerful function and low cost. In particular, the embedded network protocol stack in the system can realize the function of the router after appropriate configuration. These characteristics make Linux an ideal development platform for developing routing switching devices. Therefore, the development work of many large Internet companies requires developers to master the use of Linux system.

Complete list of common Linux commands

System operation related commands

  • System information processing
arch Displays the processor architecture of the machine

uname -m Displays the processor architecture of the machine

uname -r Displays the kernel version in use 

dmidecode -q Display hardware system components - (SMBIOS / DMI) 

hdparm -i /dev/hda List the architectural characteristics of a disk 

hdparm -tT /dev/sda Perform a test read operation on the disk 

cat /proc/cpuinfo display CPU Information about 

cat /proc/interrupts Display interrupt 

cat /proc/meminfo Verify memory usage 

cat /proc/swaps What are displayed swap Used 

cat /proc/version Displays the version of the kernel 

cat /proc/net/dev Display network adapter and statistics 

cat /proc/mounts Displays the loaded file system 

lspci -tv List all PCI equipment 

lsusb -tv display USB equipment 

date Display system date 

cal 2020 Show calendar for 2020 

date  Displays the current system time 

clock -w Save time changes to BIOS 
  • System restart and shutdown
shutdown -h now Shut down the system

init 0 Shut down the system

telinit 0 Shut down the system

shutdown -h hours:minutes & Shut down the system at a predetermined time 

shutdown -c Cancel system shutdown at scheduled time 

shutdown -r now restart

reboot restart

logout cancellation 

File operation related commands

  • File and directory operations
cd /home get into '/ home' catalogue' 

cd .. Return to the previous directory 

cd ../.. Return to the upper two directories 

cd Enter personal home directory 

cd ~user1 Enter personal home directory 

cd - Return to the last directory 

pwd Displays the current working path 

ls View files in directory 

ls -F View files in directory 

ls -l Displays details of files and directories 

ls -a Show hidden files 

ls *[0-9]* Displays the file and directory names that contain numbers 

tree Displays the tree structure of files and directories starting from the root directory

lstree Displays the tree structure of files and directories starting from the root directory

mkdir dir1 Create one called 'dir1' Directory of

mkdir dir1 dir2 Create two directories at the same time 

mkdir -p /tmp/dir1/dir2 Create a directory tree 

rm -f file1 Delete one called 'file1' File' 

rmdir dir1 Delete one called 'dir1' Directory of' 

rm -rf dir1 Delete one called 'dir1' And delete its contents at the same time 

rm -rf dir1 dir2 Delete both directories and their contents at the same time 

mv dir1 new_dir rename/Move a directory 

cp file1 file2 Copy a file 

cp dir/* . Copy all files in a directory to the current working directory 

cp -a /tmp/dir1 . Copy a directory to the current working directory 

cp -a dir1 dir2 Copy a directory 

ln -s file1 lnk1 Create a soft link to a file or directory 

ln file1 lnk1 Create a physical link to a file or directory 

touch -t YYMMDDhhmm file1 Modify the timestamp of a file or directory

iconv -l List known codes 
  • File search operation
find / -name file1 from '/' Start searching the root file system for files and directories 

find / -user user1 Search for users 'user1' Files and directories for 

find /home/user1 -name \*.bin In directory '/ home/user1' Search with'.bin' End of file 

find /usr/bin -type f -atime +100 Search for executables that have not been used in the past 100 days 

find /usr/bin -type f -mtime -10 Search for files created or modified within 10 days 

find / -name \*.rpm -exec chmod 755 '{}' \; Search to '.rpm' End the file and define its permissions 

find / -xdev -name \*.rpm Search to '.rpm' End of the file, ignoring the CD-ROM drive, flash drive and other removable devices 

locate \*.ps Look for'.ps'End of file

whereis halt Displays a binary file, source code, or man Location of 

which halt Displays the full path of a binary or executable file 
  • File mount system
mount /dev/hda2 /mnt/hda2 Mount one called hda2 Disk - Determine directory '/ mnt/hda2' Already exists 

umount /dev/hda2 Uninstall a file called hda2 Disk - From the mount point '/ mnt/hda2' sign out 

user -km /mnt/hda2 Force uninstall when device is busy 

umount -n /mnt/hda2 Run unload without writing /etc/mtab file- This is useful when the file is read-only or when the disk is full 

mount /dev/fd0 /mnt/floppy Mount a floppy disk 

mount /dev/cdrom /mnt/cdrom Mount one cdrom or dvdrom 

mount /dev/hdc /mnt/cdrecorder Mount one cdrw or dvdrom 

mount /dev/hdb /mnt/cdrecorder Mount one cdrw or dvdrom 

mount -o loop file.iso /mnt/cdrom Mount a file or ISO Mirror file 

mount -t vfat /dev/hda5 /mnt/hda5 Mount one Windows FAT32 file system 

mount /dev/sda1 /mnt/usbdisk Mount one usb Flash disk or flash memory device 

mount -t smbfs -o username=user,password=pass //WinClient/share /mnt/share mount a windows network share 
  • File permission Operation
ls -lh Display permissions 

ls /tmp | pr -T5 -W$COLUMNS Divide the terminal into 5 columns for display 

chmod ugo+rwx directory1 Set the owner of the directory(u),group (g)And others(o)To read( r ),write(w)And Implementation(x)Permissions for 

chmod go-rwx directory1 Delete Group (g)With others(o)Read / write execute permissions on the directory 

chown user1 file1 Change the owner attribute of a file 

chown -R user1 directory1 Change the owner attribute of a directory and change the attributes of all files in the directory at the same time 

chgrp group1 file1 Change the group of files 

chown user1:group1 file1 Change the owner and group properties of a file 

find / -perm -u+s List all used in a system SUID Controlled documents 

chmod u+s /bin/file1 Set the of a binary file SUID position - The user running the file is also given the same permissions as the owner 

chmod u-s /bin/file1 Disable a binary SUID position 

chmod g+s /home/public Set the of a directory SGID position - similar SUID ,But this is for directories 

chmod g-s /home/public Disable of a directory SGID position 

chmod o+t /home/public Set the of a file STIKY position - Only legal owners are allowed to delete files 

chmod o-t /home/public Disable of a directory STIKY position 
  • Special properties of files
chattr +a file1 Only files are allowed to be read and written in append mode 

chattr +c file1 Allow this file to be automatically compressed by the kernel/decompression 

chattr +d file1 During file system backup, dump The program will ignore this file 

chattr +i file1 A file that is set to immutable and cannot be deleted, modified, renamed, or linked 

chattr +s file1 Allow a file to be safely deleted 

chattr +S file1 Once the application program performs a write operation on the file, the system will immediately write the modified results to disk 

chattr +u file1 If a file is deleted, the system will allow you to restore the deleted file later 

lsattr Show special properties
  • Packaging and compressing files
bunzip2 file1.bz2 Unzip a file called 'file1.bz2'File 

bzip2 file1 Compress one called 'file1' File 

gunzip file1.gz Unzip a file called 'file1.gz'File 

gzip file1 Compress one called 'file1'File 

gzip -9 file1 Maximum compression 

rar a file1.rar test_file Create one called 'file1.rar' My bag 

rar a file1.rar file1 file2 dir1 Simultaneous compression 'file1', 'file2' And catalog 'dir1' 

unrar x file1.rar decompression rar package 

tar -cvf archive.tar file1 Create an uncompressed tarball 

tar -cvf archive.tar file1 file2 dir1 Create one that contains 'file1', 'file2' as well as 'dir1'File of 

tar -tf archive.tar Displays the contents of a package 

tar -xvf archive.tar Release a package 

tar -xvf archive.tar -C /tmp Release the compressed package to /tmp Directory 

tar -cvfj archive.tar.bz2 dir1 Create a bzip2 Compressed package in format 

tar -jxvf archive.tar.bz2 Unzip one bzip2 Compressed package in format 

tar -cvfz archive.tar.gz dir1 Create a gzip Compressed package in format 

tar -zxvf archive.tar.gz Unzip one gzip Compressed package in format 

zip file1.zip file1 Create a zip Compressed package in format 

zip -r file1.zip file1 file2 dir1 Compress several files and directories into one at the same time zip Compressed package in format 

unzip file1.zip Unzip one zip Format compressed package 
  • view file contents
cat file1 View the contents of the file forward from the first byte 

cat file1 file2 The contents of files 1 and 2 are displayed at the same time

cat file1 file2 > mfile Will file file1 And documents file2 Save in file after merging mfile

tac file1 View the contents of a file in reverse from the last line 

more file1 View the contents of a long file 

less file1 be similar to 'more' Command, but it allows the same reverse operation as the forward operation in the file 

head -2 file1 View the first two lines of a file 

head -v file1 Display file file1 And give the file title name

tail -2 file1 View the last two lines of a file 

tail -c 10 file1 View the last 10 characters of the file

tail -f /var/log/messages View the content added to a file in real time
  • text processing
cat file1 | command( sed, grep, awk, grep, etc...) > result.txt Merge the detailed description text of a file and write the introduction to a new file 

cat file1 | command( sed, grep, awk, grep, etc...) >> result.txt Merge the detailed description text of a file and write the introduction to an existing file 

grep Aug /var/log/messages In file '/var/log/messages'Find keywords in"Aug" 

grep ^Aug /var/log/messages In file '/var/log/messages'Find in to"Aug"Starting vocabulary 

grep [0-9] /var/log/messages choice '/var/log/messages' All lines in the file that contain numbers 

grep Aug -R /var/log/* Search the directory '/ var/log' and subsequent directories for the string "Aug" 

sed 's/stringa1/stringa2/g' example.txt Replace "string1" with "string2" in the example.txt file 

sed '/^$/d' example.txt Delete all blank lines from the example.txt file 

sed '/ *#/d; /^$/d' example.txt Remove all comments and blank lines from the example.txt file 

echo 'esempio' | tr '[:lower:]' '[:upper:]' Merge upper and lower cell contents 

sed -e '1d' result.txt Exclude the first line from the file example.txt 

sed -n '/stringa1/p' View rows that contain only the term "string1" 

sed -e 's/ *$//' example.txt Delete the last white space character of each line 

sed -e 's/stringa1//g' example.txt Remove only the term "string1" from the document and leave all remaining 

sed -n '1,5p;5q' example.txt View the contents from line 1 to line 5 

sed -n '5p;5q' example.txt View line 5 

sed -e 's/00*/0/g' example.txt Replacing multiple zeros with a single zero 

cat -n file1 Indicates the number of lines in the file 

cat example.txt | awk 'NR%2==1' delete example.txt All even lines in the file 

echo a b c | awk '{print $1}' View the first column of a row 

echo a b c | awk '{print $1,$3}' View the first and third columns of a row 

paste file1 file2 Merge the contents of two files or two columns 

paste -d '+' file1 file2 Merge the contents of two files or two columns, with"+"distinguish 

sort file1 file2 Sort the contents of two files 

sort file1 file2 | uniq Take out the union of two files(Keep only one copy of duplicate lines) 

sort file1 file2 | uniq -u Delete the intersection and leave other rows 

sort file1 file2 | uniq -d Take out the intersection of two files(Only files that exist in both files are left) 

comm -1 file1 file2 Compare the contents of two files and delete only 'file1' Content included 

comm -2 file1 file2 Compare the contents of two files and delete only 'file2' Content included 

comm -3 file1 file2 Compare the contents of two files and delete only the parts common to the two files 
  • Character setting and file format conversion
dos2unix filedos.txt fileunix.txt Change the format of a text file from MSDOS convert to UNIX 

unix2dos fileunix.txt filedos.txt Change the format of a text file from UNIX convert to MSDOS 

recode ..HTML < page.txt > page.html Convert a text file to html 

recode -l | more Displays all allowed conversion formats 

  • File system analysis
badblocks -v /dev/hda1 check the disk hda1 Bad magnet on 

fsck /dev/hda1 repair/inspect hda1 On disk linux File system integrity 

fsck.ext2 /dev/hda1 repair/inspect hda1 On disk ext2 File system integrity 

e2fsck /dev/hda1 repair/inspect hda1 On disk ext2 File system integrity 

e2fsck -j /dev/hda1 repair/inspect hda1 On disk ext3 File system integrity 

fsck.ext3 /dev/hda1 repair/inspect hda1 On disk ext3 File system integrity 

fsck.vfat /dev/hda1 repair/inspect hda1 On disk fat File system integrity 

fsck.msdos /dev/hda1 repair/inspect hda1 On disk dos File system integrity 

dosfsck /dev/hda1 repair/inspect hda1 On disk dos File system integrity 
  • Initialize a file system
mkfs /dev/hda1 stay hda1 Partition creates a file system 

mke2fs /dev/hda1 stay hda1 Create a partition linux ext2 File system for 

mke2fs -j /dev/hda1 stay hda1 Create a partition linux ext3(Log type)File system for 

mkfs -t vfat 32 -F /dev/hda1 Create a FAT32 file system 

fdformat -n /dev/fd0 Format a floppy disk 

mkswap /dev/hda3 Create a swap file system 
  • SWAP file system
mkswap /dev/hda3 Create a swap file system 

swapon /dev/hda3 Enable a new swap file system 

swapon /dev/hda2 /dev/hdb3 Enable both swap partition 

Disk space related commands

df -h Displays a list of mounted partitions 

ls -lSr |more Arrange files and directories in size 

du -sh dir1 Estimate catalog 'dir1' Disk space used' 

du -sk * | sort -rn Displays the size of files and directories in turn based on capacity 

rpm -q -a --qf '%10{SIZE}t%{NAME}n' | sort -k1,1n Displays installed in order of size rpm Space used by the package (fedora, redhat Class system) 

dpkg-query -W -f='${Installed-Size;10}t${Package}n' | sort -k1,1n Displays installed based on size deb Space used by the package (ubuntu, debian Class system) 

User group related commands

groupadd group_name Create a new user group 

groupdel group_name Delete a user group 

groupmod -n new_group_name old_group_name Rename a user group 

useradd -c "Name Surname " -g admin -d /home/user1 -s /bin/bash user1 Create a file that belongs to "admin" Users of user group 

useradd user1 Create a new user 

userdel -r user1 Delete a user ( '-r' Exclude home directory) 

usermod -c "User FTP" -g system -d /ftp/user1 -s /bin/nologin user1 Modify user properties 

passwd Change password 

passwd user1 Change a user's password (Only allowed root implement) 

chage -E 2005-12-31 user1 Set the expiration date of the user password 

pwck inspect '/etc/passwd' File format and syntax corrections and existing users 

grpck inspect '/etc/passwd' File format and syntax corrections and existing groups 

newgrp group_name Log in to a new group to change the default group of the newly created file

Fedora, Redhat and similar system related commands

  • RPM package command
rpm -ivh package.rpm Install one rpm package 

rpm -ivh --nodeeps package.rpm Install one rpm Package and ignore dependency warnings 

rpm -U package.rpm Update a rpm Package without changing its configuration file 

rpm -F package.rpm Update a that is determined to be installed rpm package 

rpm -e package_name.rpm Delete a rpm package 

rpm -qa Displays all installed in the system rpm package 

rpm -qa | grep httpd Show all names that contain "httpd" Typewritten rpm package 

rpm -qi package_name Get special information about an installed package 

rpm -qg "System Environment/Daemons" Displays the of a component rpm package 

rpm -ql package_name Displays an installed rpm List of files provided by package 

rpm -qc package_name Displays an installed rpm List of profiles provided by the package 

rpm -q package_name --whatrequires Display with one rpm List of package dependencies 

rpm -q package_name --whatprovides Show a rpm Volume occupied by package 

rpm -q package_name --scripts Show in installation/Scripts executed during deletion l 

rpm -q package_name --changelog Show a rpm Modification history of package 

rpm -qf /etc/httpd/conf/httpd.conf Confirm which document is given by rpm Provided by package 

rpm -qp package.rpm -l Display by a not yet installed rpm List of files provided by package 

rpm --import /media/cdrom/RPM-GPG-KEY Import public key digital certificate 

rpm --checksig package.rpm Confirm one rpm Package integrity 

rpm -qa gpg-pubkey Confirm all installed rpm Package integrity 

rpm -V package_name Check file size, license, type, owner, group MD5 Check and last modification time 

rpm -Va Check all installed in the system rpm package- Use with care 

rpm -Vp package.rpm Confirm one rpm Package not installed 

rpm2cpio package.rpm | cpio --extract --make-directories *bin* From one rpm Package run executable 

rpm -ivh /usr/src/redhat/RPMS/`arch`/package.rpm From one rpm The source code installs a built package 

rpmbuild --rebuild package_name.src.rpm From one rpm Source code to build a rpm package
  • YUM package Updater
yum install package_name Download and install a rpm package 

yum localinstall package_name.rpm One will be installed rpm Package, use your own software warehouse to solve all dependencies for you 

yum update package_name.rpm Update all installed in the current system rpm package 

yum update package_name Update a rpm package 

yum remove package_name Delete a rpm package 

yum list Lists all packages installed in the current system 

yum search package_name stay rpm Search for packages in the warehouse 

yum clean packages clear rpm Cache delete downloaded packages 

yum clean headers Delete all header files 

yum clean all Delete all cached packages and header files  

Debian, Ubuntu and similar system related commands

  • DEB package
dpkg -i package.deb install/Update a deb package 

dpkg -r package_name Delete a from the system deb package 

dpkg -l Displays all installed in the system deb package 

dpkg -l | grep httpd Show all names that contain "httpd" Typewritten deb package 

dpkg -s package_name Get information about a special package that has been installed in the system 

dpkg -L package_name Displays one that is already installed in the system deb List of files provided by the package 

dpkg --contents package.deb Displays a list of files provided by a package that has not been installed 

dpkg -S /bin/ping Confirm which document is given by deb Package provision 
  • APT software tools
apt-get install package_name install/Update a deb package

apt-cdrom install package_name Install from CD/Update a deb package 

apt-get update Upgrade packages in the list 

apt-get upgrade Upgrade all installed software 

apt-get remove package_name Delete a from the system deb package 

apt-get check Confirm that the dependent software warehouse is correct 

apt-get clean Clean cache from downloaded packages 

apt-cache search searched-package Returns the package name containing the string to search for

Backup and CD related commands

  • Backup operation
dump -0aj -f /tmp/home0.bak /home Make one '/home' Full backup of directory 

dump -1aj -f /tmp/home0.bak /home Make one '/home' Interactive backup of directories 

restore -if /tmp/home0.bak Restore an interactive backup 

rsync -rogpav --delete /home /tmp Synchronize directories on both sides 

rsync -rogpav -e ssh --delete /home ip_address:/tmp adopt SSH passageway rsync 

rsync -az -e ssh --delete ip_addr:/home/public /home/local adopt ssh And compression synchronizes a remote directory to a local directory 

rsync -az -e ssh --delete /home/local ip_addr:/home/public adopt ssh And compression synchronize local directories to remote directories 

dd bs=1M if=/dev/hda | gzip | ssh user@ip_addr 'dd of=hda.gz' adopt ssh Perform a backup of the local disk on the remote host 

dd if=/dev/sda of=/tmp/file1 Backup disk contents to a file 
tar -Puf backup.tar /home/user Perform a pair of '/home/user' Interactive backup operation of directory 

( cd /tmp/local/ && tar c . ) | ssh -C user@ip_addr 'cd /home/share/ && tar x -p' adopt ssh Copy the contents of a directory in a remote directory 

( tar c /home ) | ssh -C user@ip_addr 'cd /home/backup-home && tar x -p' adopt ssh Copy a local directory in a remote directory 

tar cf - . | (cd /tmp/backup ; tar xf - ) Locally copy a directory to another place, retaining the original permissions and links 

find /home/user1 -name '*.txt' | xargs cp -av --target-directory=/home/backup/ --parents Find and copy all from one directory to '.txt' End file to another directory 

find /var/log -name '*.log' | tar cv --files-from=- | bzip2 > log.tar.bz2 Find all to '.log' End the file and make a bzip package 

dd if=/dev/hda of=/dev/fd0 bs=512 count=1 Make a will MBR (Master Boot Record)The act of copying content to a floppy disk 

dd if=/dev/fd0 of=/dev/hda bs=512 count=1 Restore from a backup that has been saved to a floppy disk MBR content 

  • Disc operation
cdrecord -v gracetime=2 dev=/dev/cdrom -eject blank=fast -force Empty the contents of a reproducible disc 

mkisofs /dev/cdrom > cd.iso Create a disc on disk iso Mirror file 

mkisofs /dev/cdrom | gzip > cd_iso.gz Create a compressed disc on the disk iso Mirror file 

mkisofs -J -allow-leading-dots -R -V "Label CD" -iso-level 4 -o ./cd.iso data_cd Create a directory iso Mirror file 

cdrecord -v dev=/dev/cdrom cd.iso Burn a ISO Mirror file 

gzip -dc cd_iso.gz | cdrecord dev=/dev/cdrom - Burn a compressed ISO Mirror file 

mount -o loop cd.iso /mnt/iso Mount one ISO Mirror file 

cd-paranoia -B From one CD CD transcribe track to wav In the file 

cd-paranoia -- "-3" From one CD CD transcribe track to wav In file (parameter)-3) 

cdrecord --scanbus Scan the bus to identify scsi passageway 
dd if=/dev/hdc | md5sum Verify the of a device md5sum Code, e.g. a CD

Ethernet and WIFI wireless related commands

ifconfig eth0 Displays the configuration of an Ethernet card 

ifup eth0 Enable a 'eth0' network equipment  

ifdown eth0 Disable one 'eth0' network equipment  

ifconfig eth0 192.168.1.1 netmask 255.255.255.0 control IP address 

ifconfig eth0 promisc set up 'eth0' Shuffle mode to sniff packets (sniffing) 

dhclient eth0 with dhcp Mode enable 'eth0' 

route -n show routing table 

route add -net 0/0 gw IP_Gateway configura default gateway 

route add -net 192.168.0.0 netmask 255.255.0.0 gw 192.168.1.1 configure static route to reach network '192.168.0.0/16' 

This article is reproduced from official account: testing development technology.
Original link: https://mp.weixin.qq.com/s/OV74DBE8BrI1fkkmdMieqw

Tags: Linux Operation & Maintenance CentOS

Posted on Thu, 09 Sep 2021 16:50:36 -0400 by berrberr