Every Blog Post
You have millions of Weibo posts you want to write, but some are simply unimportant. Later, you realize that it was your fear of being seen through by others that made you bury the truth in everyday life. You have countless things to say, but when you open that dialogue box, you can't type a single word. You understand now that you were afraid of being seen through from the very beginning, so you would rather be lonely. You would rather laugh every day than let people see that you have truly suffered. Only in the deepest night can you allow yourself to feel sad.
Do not change your passion, your sincerity, your effort. Growth is not about becoming unrecognizable, but about preserving the important things and moving forward with all your might.
Live each day fully, regardless of whether others agree or care. There are so many people in this world, and the rest of your life is long; there will always be someone who appreciates you. Even when the sun sets, there are a thousand colors.
It’s nothing; everyone is different. If they don’t like it, then they just don’t like it. Those songs keep playing in the headphones, touching those who can understand them. But there are moments when I still feel unwilling. I know you feel unwilling too. What you are unwilling about is that those you truly care about are drifting further away from you. You clearly cherish them, but you cannot accept that friends are becoming fewer; you clearly treat people sincerely, but that person turns around and speaks ill of you to others; you clearly did nothing wrong, yet some people force you to apologize. Sometimes you doubt whether your set of principles is suitable for your current social situation. What can you do? You know their little tricks, you know their actions, but you just can’t be like them. When you watch a movie, you turn on the vibration, never making loud noises; you are used to saying thank you to waiters and being polite to everyone. You can’t change because to you, this is your daily life; it would be strange not to be this way.
—— Lu Sihao "You Have Walked a Long Way"
Table of Contents
-
Summary of 600 Powerful Linux Commands
-
Every Blog Post
-
1. Basic Commands
-
2. Shutdown
-
3. Files and Directories
-
4. File Search
-
5. Mounting a Filesystem
-
6. Disk Space
-
7. Users and Groups
-
8. File Permissions, use “+” to set permissions, use “-” to cancel
-
9. Special File Attributes, use “+” to set permissions, use “-” to cancel
-
10. Packing and Compressing Files
-
11. RPM Packages
-
12. YUM Package Updater
-
13. DEB Packages
-
14. Viewing File Contents
-
15. Text Processing
-
16. Character Settings and File Format Conversion
-
17. Filesystem Analysis
-
18. Initializing a Filesystem
-
19. SWAP Filesystem
-
20. Backup
-
21. CD-ROM
-
22. Networking (Ethernet and WIFI)
-
23. Listing Directory Contents
-
24. Viewing File Types
-
25. Copying Files and Directories
-
26. Common System Commands
-
27. VIM
-
28. Package Management Commands (RPM)
-
29. Conclusion:
Today, I bring you a very comprehensive article summarizing Linux commands, which are also highly used in daily work.
1. Basic Commands
uname -m Display the machine's processor architecture
uname -r Display the currently used kernel version
dmidecode -q Display hardware system components (SMBIOS / DMI)
hdparm -i /dev/hda List a disk's architectural features
hdparm -tT /dev/sda Perform a test read operation on the disk
arch Display the machine's processor architecture
uname -m Display the machine's processor architecture
uname -r Display the currently used kernel version
dmidecode -q Display hardware system components - (SMBIOS / DMI)
hdparm -i /dev/hda List a disk's architectural features
hdparm -tT /dev/sda Perform a test read operation on the disk
cat /proc/cpuinfo Display CPU info
cat /proc/interrupts Display interrupts
cat /proc/meminfo Check memory usage
cat /proc/swaps Display which swap is being used
cat /proc/version Display kernel version
cat /proc/net/dev Display network adapters and statistics
cat /proc/mounts Display loaded filesystems
lspci -tv List PCI devices
lsusb -tv Display USB devices
date Display system date
cal 2007 Display the calendar for the year 2007
date 041217002007.00 Set date and time - month day hour minute year.second
clock -w Save time modification to BIOS
2. Shutdown
shutdown -h now Shut down the system (1)
init 0 Shut down the system (2)
telinit 0 Shut down the system (3)
shutdown -h hours:minutes & 按预定时间关闭系统
shutdown -c Cancel scheduled shutdown
shutdown -r now Restart (1)
reboot Restart (2)
logout Log out
3. Files and Directories
cd /home Enter the '/home' directory
cd .. Return to the previous directory
cd ../.. Return to two levels up
cd Enter the user's home directory
cd ~user1 Enter the home directory of user1
cd - Return to the last directory
pwd Display the working path
ls View files in the directory
ls -F View files in the directory
ls -l Display detailed information about files and directories
ls -a Display hidden files
ls *[0-9]* Display filenames and directory names containing numbers
tree Display the tree structure of files and directories starting from the root directory (1)
lstree Display the tree structure of files and directories starting from the root directory (2)
mkdir dir1 Create a directory named 'dir1'
mkdir dir1 dir2 Create two directories at once
mkdir -p /tmp/dir1/dir2 Create a directory tree
rm -f file1 Delete a file named 'file1'
rmdir dir1 Delete a directory named 'dir1'
rm -rf dir1 Delete a directory named 'dir1' and its contents
rm -rf dir1 dir2 Delete two directories and their contents at once
mv dir1 new_dir Rename/move a directory
cp file1 file2 Copy a file
cp dir1/* . Copy all files from 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 hard link to a file or directory
touch -t 0712250000 file1 Modify the timestamp of a file or directory - (YYMMDDhhmm)
file file1 outputs the mime type of the file as text
iconv -l List known encodings
iconv -f fromEncoding -t toEncoding inputFile > outputFile creates a new file from the given input file by assuming it is encoded in fromEncoding and converting it to toEncoding.
find . -maxdepth 1 -name *.jpg -print -exec convert "{}" -resize 80x60 "thumbs/{}" \; batch resize files in the current directory and send them to a thumbnails directory (requires convert from Imagemagick)
4. File Search
find / -name file1 Search for files and directories starting from '/' in the root filesystem
find / -user user1 Search for files and directories belonging to user 'user1'
find /home/user1 -name *.bin Search for files ending with '.bin' in the directory '/home/user1'
find /usr/bin -type f -atime +100 Search for executable files that have not been used in the past 100 days
find /usr/bin -type f -mtime -10 Search for files created or modified in the last 10 days
find / -name *.rpm -exec chmod 755 '{}' \; Search for files ending with '.rpm' and set their permissions
find / -xdev -name *.rpm Search for files ending with '.rpm', ignoring removable devices like CD-ROMs and USB drives
locate *.ps Find files ending with '.ps' - first run 'updatedb' command
whereis halt Show the location of a binary file, source, or man
which halt Show the full path of a binary file or executable
5. Mounting a Filesystem
mount /dev/hda2 /mnt/hda2 Mount a disk named hda2 - ensure the directory '/mnt/hda2' already exists
umount /dev/hda2 Unmount a disk named hda2 - first exit from the mount point '/mnt/hda2'
fuser -km /mnt/hda2 Force unmount when the device is busy
umount -n /mnt/hda2 Run unmount operation without writing to /etc/mtab - very 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 a CD-ROM or DVD-ROM
mount /dev/hdc /mnt/cdrecorder Mount a CD-RW or DVD-ROM
mount /dev/hdb /mnt/cdrecorder Mount a CD-RW or DVD-ROM
mount -o loop file.iso /mnt/cdrom Mount a file or ISO image file
mount -t vfat /dev/hda5 /mnt/hda5 Mount a Windows FAT32 filesystem
mount /dev/sda1 /mnt/usbdisk Mount a USB flash drive or disk
mount -t smbfs -o username=user,password=pass //WinClient/share /mnt/share Mount a Windows network share
6. Disk Space
df -h Display a list of mounted partitions
ls -lSr | more List files and directories sorted by size
du -sh dir1 Estimate the disk space used by directory 'dir1'
du -sk * | sort -rn Display the size of files and directories in descending order
rpm -q -a --qf '%10{SIZE}t%{NAME}n' | sort -k1,1n Display the space used by installed RPM packages sorted by size (Fedora, RedHat systems)
dpkg-query -W -f='${Installed-Size;10}t${Package}n' | sort -k1,1n Display the space used by installed DEB packages sorted by size (Ubuntu, Debian systems)
7. Users and Groups
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 user belonging to the "admin" user group
useradd user1 Create a new user
userdel -r user1 Delete a user ('-r' excludes the home directory)
usermod -c "User FTP" -g system -d /ftp/user1 -s /bin/nologin user1 Modify user attributes
passwd Change password
passwd user1 Change a user's password (only allowed for root)
chage -E 2005-12-31 user1 Set a user's password expiration date
pwck Check the format and syntax of the '/etc/passwd' file and correct existing users
grpck Check the format and syntax of the '/etc/passwd' file and correct existing groups
newgrp group_name Log into a new group to change the default group for newly created files
8. File Permissions, use “+” to set permissions, use “-” to cancel
chattr +a file1 Allow file to be read and written only in append mode
chattr +c file1 Allow this file to be automatically compressed/decompressed by the kernel
chattr +d file1 Ignore this file during filesystem backups by the dump program
chattr +i file1 Set the file as immutable, cannot be deleted, modified, renamed, or linked
chattr +s file1 Allow a file to be securely deleted
chattr +S file1 Once an application writes to this file, the system immediately writes the modified result to disk
chattr +u file1 If the file is deleted, the system will allow you to recover the deleted file later
lsattr Display special attributes
9. Special File Attributes, use “+” to set permissions, use “-” to cancel
chattr +a file1 Allow file to be read and written only in append mode
chattr +c file1 Allow this file to be automatically compressed/decompressed by the kernel
chattr +d file1 Ignore this file during filesystem backups by the dump program
chattr +i file1 Set the file as immutable, cannot be deleted, modified, renamed, or linked
chattr +s file1 Allow a file to be securely deleted
chattr +S file1 Once an application writes to this file, the system immediately writes the modified result to disk
chattr +u file1 If the file is deleted, the system will allow you to recover the deleted file later
lsattr Display special attributes
10. Packing and Compressing Files
bunzip2 file1.bz2 Decompress a file named 'file1.bz2'
bzip2 file1 Compress a file named 'file1'
gunzip file1.gz Decompress a file named 'file1.gz'
gzip file1 Compress a file named 'file1'
gzip -9 file1 Maximum compression
rar a file1.rar test_file Create a package named 'file1.rar'
rar a file1.rar file1 file2 dir1 Compress 'file1', 'file2', and directory 'dir1' at once
rar x file1.rar Decompress rar package
unrar x file1.rar Decompress rar package
tar -cvf archive.tar file1 Create an uncompressed tarball
tar -cvf archive.tar file1 file2 dir1 Create an archive file containing 'file1', 'file2', and 'dir1'
tar -tf archive.tar Display the contents of a package
tar -xvf archive.tar Extract a package
tar -xvf archive.tar -C /tmp Extract the compressed package to the /tmp directory
tar -cvfj archive.tar.bz2 dir1 Create a bzip2 format compressed package
tar -xvfj archive.tar.bz2 Decompress a bzip2 format compressed package
tar -cvfz archive.tar.gz dir1 Create a gzip format compressed package
tar -xvfz archive.tar.gz Decompress a gzip format compressed package
zip file1.zip file1 Create a zip format compressed package
zip -r file1.zip file1 file2 dir1 Compress several files and directories into a zip format compressed package
unzip file1.zip Decompress a zip format compressed package
11. RPM Packages
rpm -ivh package.rpm Install an rpm package
rpm -ivh --nodeps package.rpm Install an rpm package while ignoring dependency warnings
rpm -U package.rpm Update an rpm package without changing its configuration files
rpm -F package.rpm Update a certain already installed rpm package
rpm -e package_name.rpm Delete an rpm package
rpm -qa Display all installed rpm packages in the system
rpm -qa | grep httpd Display all rpm packages with "httpd" in their name
rpm -qi package_name Get special information about an installed package
rpm -qg "System Environment/Daemons" Display the rpm package of a component
rpm -ql package_name Display the list of files provided by an installed rpm package
rpm -qc package_name Display the list of configuration files provided by an installed rpm package
rpm -q package_name --whatrequires Display a list of packages that have dependencies on an rpm package
rpm -q package_name --whatprovides Display the size occupied by an rpm package
rpm -q package_name --scripts Display the scripts executed during installation/deletion
rpm -q package_name --changelog Display the change history of an rpm package
rpm -qf /etc/httpd/conf/httpd.conf Confirm which rpm package provides the given file
rpm -qp package.rpm -l Display the list of files provided by an uninstalled rpm package
rpm --import /media/cdrom/RPM-GPG-KEY Import public key digital certificate
rpm --checksig package.rpm Confirm the integrity of an rpm package
rpm -qa gpg-pubkey Confirm the integrity of all installed rpm packages
rpm -V package_name Check file size, permissions, type, owner, group, MD5 checksum, and last modification time
rpm -Va Check all installed rpm packages in the system - use with caution
rpm -Vp package.rpm Confirm an rpm package that has not been installed
rpm2cpio package.rpm | cpio --extract --make-directories *bin* Run executable files from an rpm package
rpm -ivh /usr/src/redhat/RPMS/`arch`/package.rpm Install a built package from an rpm source
rpmbuild --rebuild package_name.src.rpm Build an rpm package from an rpm source
12. YUM Package Updater
yum install package_name Download and install an rpm package
yum localinstall package_name.rpm Install an rpm package, using your own software repository to resolve all dependencies
yum update package_name.rpm Update all installed rpm packages in the current system
yum update package_name Update an rpm package
yum remove package_name Delete an rpm package
yum list List all packages installed in the current system
yum search package_name Search for software packages in the rpm repository
yum clean packages Clean up rpm cache and delete downloaded packages
yum clean headers Delete all header files
yum clean all Delete all cached packages and header files
13. DEB Packages
dpkg -i package.deb Install/update a deb package
dpkg -r package_name Remove a deb package from the system
dpkg -l Display all installed deb packages in the system
dpkg -l | grep httpd Display all deb packages with "httpd" in their name
dpkg -s package_name Get information about a specific package installed in the system
dpkg -L package_name Display the list of files provided by a deb package installed in the system
dpkg --contents package.deb Display the list of files provided by a package that has not been installed
dpkg -S /bin/ping Confirm which deb package provides the given file
APT Software Tools (Debian, Ubuntu, and similar systems)
apt-get install package_name Install/update a deb package
apt-cdrom install package_name From CD install/update a deb package
apt-get update Upgrade the list of software packages
apt-get upgrade Upgrade all installed software
apt-get remove package_name Remove a deb package from the system
apt-get check Confirm that the dependency software repository is correct
apt-get clean Clean up the cache from downloaded software packages
apt-cache search searched-package Return the names of software packages containing the search string
14. Viewing File Contents
cat file1 View the contents of a file from the first byte
tac file1 View the contents of a file from the last line
more file1 View the contents of a long file
less file1 Similar to 'more' command, but allows reverse operations in the file
head -2 file1 View the first two lines of a file
tail -2 file1 View the last two lines of a file
tail -f /var/log/messages Real-time view of content added to a file
15. Text Processing
cat file1 file2 ... | command <> file1_in.txt_or_file1_out.txt General syntax for text manipulation using PIPE, STDIN and STDOUT
cat file1 | command( sed, grep, awk, grep, etc...) > result.txt Merge detailed description text from a file and write the summary to a new file
cat file1 | command( sed, grep, awk, grep, etc...) >> result.txt Merge detailed description text from a file and write the summary to an existing file
grep Aug /var/log/messages Search for the keyword "Aug" in the file '/var/log/messages'
grep ^Aug /var/log/messages Search for words starting with "Aug" in the file '/var/log/messages'
grep [0-9] /var/log/messages Select all lines in the '/var/log/messages' file that contain numbers
grep Aug -R /var/log/* Search for the string "Aug" in the '/var/log' directory and subsequent directories
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 Delete all comments and blank lines from the example.txt file
echo 'example' | tr '[:lower:]' '[:upper:]' Merge the contents of upper and lower cells
sed -e '1d' result.txt Exclude the first line from the example.txt file
sed -n '/stringa1/p' View only the lines containing the word "string1"
sed -e 's/ *$//' example.txt Delete the last whitespace character from each line
sed -e 's/stringa1//g' example.txt Only delete the word "string1" from the document and keep the rest
sed -n '1,5p;5q' example.txt View the content from the first to the fifth line
sed -n '5p;5q' example.txt View the fifth line
sed -e 's/00*/0/g' example.txt Replace multiple zeros with a single zero
cat -n file1 Number the lines of the file
cat example.txt | awk 'NR%2==1' Delete all even lines from the example.txt file
echo a b c | awk '{print $1}' View the first column of a line
echo a b c | awk '{print $1,$3}' View the first and third columns of a line
paste file1 file2 Merge the contents of two files or columns
paste -d '+' file1 file2 Merge the contents of two files or columns, separated by a "+"
sort file1 file2 Sort the contents of two files
sort file1 file2 | uniq Take the union of two files (only keep one copy of duplicate lines)
sort file1 file2 | uniq -u Delete the intersection, leaving other lines
sort file1 file2 | uniq -d Take the intersection of two files (only keep lines that exist in both files)
comm -1 file1 file2 Compare the contents of two files, only delete the contents contained in 'file1'
comm -2 file1 file2 Compare the contents of two files, only delete the contents contained in 'file2'
comm -3 file1 file2 Compare the contents of two files, only delete the common parts of both files
16. Character Settings and File Format Conversion
dos2unix filedos.txt fileunix.txt Convert a text file format from MSDOS to UNIX
unix2dos fileunix.txt filedos.txt Convert a text file format from UNIX to MSDOS
recode ..HTML < page.txt > page.html Convert a text file to html
recode -l | more Display all allowed conversion formats
17. Filesystem Analysis
badblocks -v /dev/hda1 Check for bad blocks on disk hda1
fsck /dev/hda1 Repair/check the integrity of the Linux filesystem on disk hda1
fsck.ext2 /dev/hda1 Repair/check the integrity of the ext2 filesystem on disk hda1
e2fsck /dev/hda1 Repair/check the integrity of the ext2 filesystem on disk hda1
e2fsck -j /dev/hda1 Repair/check the integrity of the ext3 filesystem on disk hda1
fsck.ext3 /dev/hda1 Repair/check the integrity of the ext3 filesystem on disk hda1
fsck.vfat /dev/hda1 Repair/check the integrity of the fat filesystem on disk hda1
fsck.msdos /dev/hda1 Repair/check the integrity of the dos filesystem on disk hda1
dosfsck /dev/hda1 Repair/check the integrity of the dos filesystem on disk hda1
18. Initializing a Filesystem
mkfs /dev/hda1 Create a filesystem on partition hda1
mke2fs /dev/hda1 Create a Linux ext2 filesystem on partition hda1
mke2fs -j /dev/hda1 Create a Linux ext3 (journaled) filesystem on partition hda1
mkfs -t vfat 32 -F /dev/hda1 Create a FAT32 filesystem
fdformat -n /dev/fd0 Format a floppy disk
mkswap /dev/hda3 Create a swap filesystem
19. SWAP Filesystem
mkswap /dev/hda3 Create a swap filesystem
swapon /dev/hda3 Enable a new swap filesystem
swapon /dev/hda2 /dev/hdb3 Enable two swap partitions
20. Backup
dump -0aj -f /tmp/home0.bak /home Create a full backup of the '/home' directory
dump -1aj -f /tmp/home0.bak /home Create an interactive backup of the '/home' directory
restore -if /tmp/home0.bak Restore an interactive backup
rsync -rogpav --delete /home /tmp Synchronize both directories
rsync -rogpav -e ssh --delete /home ip_address:/tmp Rsync over SSH
rsync -az -e ssh --delete ip_addr:/home/public /home/local Synchronize a remote directory to a local directory via ssh and compression
rsync -az -e ssh --delete /home/local ip_addr:/home/public Synchronize a local directory to a remote directory via ssh and compression
dd bs=1M if=/dev/hda | gzip | ssh user@ip_addr 'dd of=hda.gz' Perform a backup of the local disk on a remote host via ssh
ddif=/dev/sda of=/tmp/file1 Backup disk content to a file
tar -Puf backup.tar /home/user Perform an interactive backup operation on the '/home/user' directory
( cd /tmp/local/ && tar c . ) | ssh -C user@ip_addr 'cd /home/share/ && tar x -p' Copy directory content to a remote directory via ssh
( tar c /home ) | ssh -C user@ip_addr 'cd /home/backup-home && tar x -p' Copy a local directory to a remote directory via ssh
tar cf - . | (cd /tmp/backup ; tar xf - ) Locally copy a directory to another place, preserving original permissions and links
find /home/user1 -name '*.txt' | xargs cp -av --target-directory=/home/backup/ --parents Find and copy all files ending with '.txt' to another directory
find /var/log -name '*.log' | tar cv --files-from=- | bzip2 > log.tar.bz2 Find all files ending with '.log' and create a bzip package
ddif=/dev/hda of=/dev/fd0 bs=512 count=1 Copy the MBR (Master Boot Record) content to a floppy disk
ddif=/dev/fd0 of=/dev/hda bs=512 count=1 Restore MBR content from a saved floppy disk
21. CD-ROM
cdrecord -v gracetime=2 dev=/dev/cdrom -eject blank=fast -force Clear the contents of a rewritable CD
mkisofs /dev/cdrom > cd.iso Create an ISO image file of a CD on disk
mkisofs /dev/cdrom | gzip > cd_iso.gz Create a compressed ISO image file of a CD on disk
mkisofs -J -allow-leading-dots -R -V "Label CD" -iso-level 4 -o ./cd.iso data_cd Create an ISO image file of a directory
cdrecord -v dev=/dev/cdrom cd.iso Burn an ISO image file
gzip -dc cd_iso.gz | cdrecord dev=/dev/cdrom - Burn a compressed ISO image file
mount -o loop cd.iso /mnt/iso Mount an ISO image file
cd-paranoia -B Transcribe audio tracks from a CD to wav files
cd-paranoia -- "-3" Transcribe audio tracks from a CD to wav files (parameter -3)
cdrecord --scanbus Scan the bus to identify SCSI channels
ddif=/dev/hdc | md5sum Check the md5sum code of a device, such as a CD
22. Networking (Ethernet and WIFI)
ifconfig eth0 Display the configuration of an Ethernet card
ifup eth0 Enable an 'eth0' network device
ifdown eth0 Disable an 'eth0' network device
ifconfig eth0 192.168.1.1 netmask 255.255.255.0 Control IP address
ifconfig eth0 promisc Set 'eth0' to promiscuous mode to sniff packets (sniffing)
dhclient eth0 Enable 'eth0' in dhcp mode
route -n Show routing table
route add -net 0/0 gw IP_Gateway Configure 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'
route del 0/0 gw IP_gateway Remove static route
echo "1" > /proc/sys/net/ipv4/ip_forward Activate IP routing
hostname Show hostname of system
host www.example.com Lookup hostname to resolve name to IP address and vice versa (1)
nslookup www.example.com Lookup hostname to resolve name to IP address and vice versa (2)
ip link show Show link status of all interfaces
mii-tool eth0 Show link status of 'eth0'
ethtool eth0 Show statistics of network card 'eth0'
netstat -tup Show all active network connections and their PID
netstat -tupl Show all network services listening on the system and their PID
tcpdump tcp port 80 Show all HTTP traffic
iwlist scan Show wireless networks
iwconfig eth1 Show configuration of a wireless network card
hostname Show hostname
host www.example.com Lookup hostname to resolve name to IP address and vice versa
nslookup www.example.com Lookup hostname to resolve name to IP address and vice versa
whois www.example.com Lookup on Whois database
23. Listing Directory Contents
ls -a: Display all files (including hidden files);
ls -l: Display detailed information;
ls -R: Recursively display subdirectory structure;
ls -ld: Display directory and link information;
ctrl+r: Search command in history (input any character in the command);
Files starting with . in Linux are hidden files;
pwd: Display current directory
24. Viewing File Types
file: View file type
25. Copying Files and Directories
1. cp: Copy files and directories cp source_file (folder) target_file (folder).
Common parameters: -r: Recursively copy the entire directory tree; -v: Display detailed information;
When copying a folder, add a -r parameter after the cp command:
For example: cp -r source_folder target_folder.
2. touch + filename: When the file does not exist, create the corresponding file; when the file exists, modify the creation time of the file.
Function: Generate an empty file or modify the access/modification time record value of the file;
touch *: Modify the file time under the current directory to the system's current time;
touch -d 20040210 test: Change the date of the test file to 20040210;
touch abc: If the abc file exists, modify it to the system's current time; if it does not exist, generate an empty file with the current time.
3. mv file target_directory: Move or rename files or directories (if a file name is specified, it can rename the file). You can move files and directories to another directory or change the names of files and directories.
Format: mv [parameters] <source_file directory="" or=""> <target_file directory="" or="">
mv a.txt ../: Move a.txt file to the upper directory
mv a.txt b.txt: Rename a.txt to b.txt
mv dir2 ../: Move dir2 directory up one level
</target_file></source_file>
4. rm: Delete files
Common parameters: -i: Interactive -r: Recursively delete all contents including directories.
5. mkdir + folder name: Create a folder
6. rm -r + folder name: Delete a folder (can delete both empty and non-empty folders);
rmdir folder name: Delete a folder (can only delete empty folders).
7. mkdir -p dir1/dir2: Create dir1 directory under the current directory, and create dir2 directory under dir1 directory, which means consecutively creating two directories (dir1/ and dir1/dir2).
8. rmdir -p dir1/dir2: Delete the dir2 directory under dir1, and if the dir1 directory is empty, delete it as well.
9. rm *: Delete all files under the current directory
10. -f parameter: Force delete files rm -f *.txt: Force delete all files with the suffix .txt.
11. -i parameter: Ask for confirmation when deleting files
rm -i *: Deleting all files in the current directory will prompt:
rm: backup: is a directory will skip when encountering a directory
rm: remove 'myfiles.txt'? Y
When deleting files, you can press Y or N to allow or refuse to delete the file.
12. -r parameter: Recursively delete (delete all subdirectories as well, this is a very common parameter).
rm -r test: Delete the test directory (including all files and subdirectories under the test directory);
rm -r *: Delete all files (including all files in the current directory, all subdirectories, and files under subdirectories) Generally, when deleting directories, r and f are used together to avoid trouble;
rm -rf test: Force delete without asking.
13. grep: Function: Search for matching characters in a file and output.
Format: grep [parameters] <string find="" to=""> <source file="" search="" to=""/>
grep linux test.txt: Search for the string linux in the test.txt file and output.
</string>
14. ln command
Function: Establish links between files and directories
Format: ln [parameters] <source directory="" file="" or=""/> <target directory="" file="" or="">
Links are divided into "soft links" and "hard links"
1. Soft link:
ln -s /usr/share/do doc: Create a link file doc, pointing to the directory /usr/share/do
2. Hard link:
ln /usr/share/test hard: Create a hard link file hard, which means that for the storage area corresponding to the test file, there is now another file pointing to it.
</target>
26. Common System Commands
1. Display Commands
date: View or set the current system time: Format display time: +%Y--%m--%d;
date -s: Set the current system time;
hwclock(clock): Display hardware clock time (requires administrator privileges);
cal: View calendar;
Format cal [parameters] month year;
cal: Display the current month's calendar cal4 2004: Display the calendar for April 2004;
cal -y 2003: Display the calendar for the year 2003;
uptime: View system uptime
2. Output Viewing Commands
2. Output Viewing Commands
echo: Display input content Append file echo "liuyazhuang" >> liuyazhuang.txt
cat: Display file content, can also merge several files into one file;
Format: cat [parameters] <filename>
cat test.txt: Display the content of test.txt file;
cat test.txt | more: Display the content of test.txt file page by page;
cat test.txt >> test1.txt: Append the content of test.txt to test1.txt;
cat test.txt test2.txt > readme.txt: Merge test.txt and test2.txt files into readme.txt file;
head: Display the first few lines of a file (default 10 lines) -n: Specify the number of lines to display format: head -n filename;
tail: Display the last few lines of a file (default 10 lines) -n: Specify the number of lines -f: Track and display file updates (generally used to view logs, the command will not exit, but will continuously display new content added);
Format: tail [parameters] <filename>;
tail -10 /etc/passwd: Display the last 10 lines of the /etc/passwd file;
tail +10 /etc/passwd: Display the content of the /etc/passwd file from the 10th line to the end;
more: Used to display file content page by page (can only scroll down);
The more command is generally used when the content to be displayed exceeds one screen length. To avoid the content flashing by instantly, users can use the more command to pause when the screen is full. At this time, you can press the space bar to continue displaying the next screen, or press the Q key to stop displaying;
ls -al | more: Display the file list in the etc directory in long format, pausing when the screen is full, you can press the space bar to continue displaying the next screen, or press the Q key to exit;
less: Page through file content (with up and down scrolling) Press the up key to page, press q to exit;
the less command is similar to the more command, and can also be used to browse files that exceed one page. The difference is that the less command allows scrolling up and down the file, while the more command only allows scrolling down. When you want to end browsing, just press the Q key at the prompt of the less command.
ls -al | less: List all contents in the /etc directory in long format. Users can scroll up and down or press the Q key to exit.
</filename></filename>
3. Viewing Hardware Information
3. Viewing Hardware Information
Ispci: View PCI devices -v: View detailed information
Isusb: View USB devices -v: View detailed information
Ismod: View loaded modules (drivers)
4. Shutdown, Restart
4. Shutdown, Restart
shutdown Close, restart the computer
shutdown [shutdown, restart] time -h Shut down the computer -r: Restart the computer
For example: Shut down immediately: shutdown -h now
Shut down after 10 minutes: shutdown -h +10
Shut down at 23:30: shutdown -h 23:30
Restart immediately: shutdown -r now
poweroff: Shut down the computer immediately
reboot: Restart the computer immediately
5. Archiving, Compressing
5. Archiving, Compressing
zip: Compress files zip liuyazhuang.zip myfile Format: "zip compressed zip file name"
unzip: Decompress files unzip liuyazhuang.zip
gzip: Compress files gzip filename
tar: Archive files
tar -cvf out.tar liuyazhuang Package an archive (pack the file "liuyazhuang" into an archive)
tar -xvf liuyazhuang.tar Extract an archive (extract the liuyazhuang.tar archive)
tar -cvzf backup.tar.gz /etc
-z parameter compresses the archived file to reduce size.
-c: Create a new tar file
-v: Display the information of the running process
-f: Specify the file name
-z: Call the gzip compression command for compression
-t: View the contents of the compressed file
-x: Unpack the tar file
tar -cvf test.tar *: Pack all files into test.tar, the extension .tar must be added manually
tar -zcvf test.tar.gz *: Pack all files into test.tar, then compress it with the gzip command
tar -tf test.tar: View what files are included in the test.tar file
tar -xvf test.tar: Unpack test.tar
tar -zxvf foo.tar.gz: Decompress
gzip and gunzip commands
gzip test.txt: Compress files without any parameters
gzip -l test.txt.gz: Display compression ratio
6. Searching
6. Searching
locate: Quickly find files, folders: locate keyword
This command requires a pre-established database, which is updated daily by default. You can use the updatedb command to manually establish or update the database.
find search position search parameters
For example:
find . -name *liuyazhuang* Find files containing "liuyazhuang" in the current directory
find / -name *.conf Find files with the suffix .conf in the root directory (entire hard drive)
find / -perm 777 Find all files with permission 777
find / -type d Return all directories under the root directory
find . -name "a*" -exec ls -l {} \;
find function: Used to find files or directories
Format: find [<path>] [matching conditions]
find / -name httpd.conf Search for a file named httpd.conf in the system root directory
</path>
7. ctrl+c: Terminate the current command
8. who or w command
8. who or w command
Function: View which users are logged into the current system
Format: who/w [parameters]
9. dmesg command
9. dmesg command
Function: Display system diagnostic information, operating system version number, physical memory size, and other information.
10. df command
10. df command
Function: Used to view the usage of each partition of the filesystem.
11. du command
11. du command
Function: View the hard disk space used by each level of subdirectories in a directory.
Format: du [parameters] <directory name="">
</directory>
12. free command
12. free command
Function: Used to view the size and usage of system memory and virtual memory (swap space).
27. VIM
VIM is a powerful command-line text editor, which can be started in Linux using the vim command.
Generally, use vim + target file path to use vim
If the target file exists, vim opens the target file; if the target file does not exist, vim creates and opens the file.
:q: Exit the vim editor
VIM Modes
vim has three modes:
(1) Command Mode (Normal Mode)
After vim starts, it enters command mode by default. Any mode can return to command mode by pressing the esc key (you can press it multiple times). In command mode, you can type different commands to complete selection, copy, paste, undo, and other operations.
Common commands in command mode are as follows:
i: Insert text before the cursor
o: Insert a new line below the current line
dd: Delete the entire line
yy: Put the content of the current line into the buffer (copy the current line)
n+yy: Put the content of n lines into the buffer (copy n lines)
p: Paste the text from the buffer after the cursor
u: Undo the last operation
r: Replace the current character
/ Search for keywords
(2) Insert Mode
Press the “i” key in command mode to enter insert mode, where you can input and edit text content. Use the esc key to return to command mode.
(3) Ex Mode
Press the “:” key in command mode to enter ex mode, the cursor will move to the bottom, where you can save changes or exit vim.
Common commands in ex mode are as follows:
:w: Save the current changes
:q: Exit
:q!: Force exit, save changes
:x: Save and exit, equivalent to :wq
:set number Display line numbers
:! System command Execute a system command and display the result
:sh: Switch to command line, use ctrl+d to switch back to vim
28. Package Management Commands (RPM)
1. Software Package Installation
1. Software Package Installation
Using the RPM command's installation mode can place all components of the software package in the correct paths in the system. The command to install a software package is: rpm -ivh wu-ftpd-2.6.2-8.i386.rpm
i: Action rpm's installation mode v: Verify file information h: Display installation progress
2. Software Package Deletion
2. Software Package Deletion
The deletion mode will remove all contents of the specified software package, but will not include modified configuration files. The command to delete an RPM software package is as follows: rpm -e wu-ftpd
Note: Here you must use the software name "wu-ftpd" or "wu-ftpd-2.6.2-8" instead of using the package name when it was installed, wu-ftpd-2.6.2-8.i386.rpm
3. Software Package Upgrade
3. Software Package Upgrade
The upgrade mode will install the user-specified updated version and remove the same software package already installed in the system. The command to upgrade a software package is as follows: rpm -Uvh wu-ftpd-2.6.2-8.i386.rpm -Uvh: Upgrade parameters.
4. Software Package Update
4. Software Package Update
In update mode, the rpm command will check whether the software package specified in the command line is newer than the existing software package in the system. If so, the rpm command will automatically update the specified software package; otherwise, if there is no older version of the specified package in the system, the rpm command will not install this package. In upgrade mode, regardless of whether there is an older version in the system, the rpm command will install the specified software package.
rpm -Fvh wu-ftpd-2.6.2-8.i386.rpm -Fvh: Update parameters
5. Software Package Query
5. Software Package Query
To obtain information about an RPM software package, you can use the query mode. Use the -q parameter to query the contents of an installed software package.
rpm -q wu-ftpd
Query the location where the software package is installed: rpm -ql package-name
rpm -ql xv (l parameter: Display file list)
29 Conclusion:
Due to my own limitations, there may be errors in this article. I hope everyone can provide guidance. Han Xin points soldiers – the more the better, thank you all, see you in the rivers and lakes, until we meet again!!!
Link:https://www.cnblogs.com/TheMagicalRainbowSea/p/17303384.html
(Copyright belongs to the original author, please delete if infringed)
WeChat group
WeChat group
WeChat group

To facilitate better communication on operation and maintenance and related technical issues, a WeChat group has been created. Friends who want to join the group can scan the QR code below to add me as a friend (note: join the group).

Blog
Guest
Blog

CSDN Blog: https://blog.csdn.net/qq_25599925

Juejin Blog: https://juejin.cn/user/4262187909781751

Knowledge Planet: https://wx.zsxq.com/group/15555885545422

Long press to recognize the QR code to visit the blog website and see more high-quality original content.