systemd
Systemctl start service // Start service systemctl stop service // Stop service systemctl restart service // Restart service systemctlenableService //service Start systemctldisableService //service Disable automatic startup systemctl status service // View service systemctl is-enabled service // View whether the service automatically starts upon startupCopy the code
Viewing System Information
arch Display the processor architecture of the machine
uname -m Display the processor architecture of the machine
uname -r Display the kernel version in use
dmidecode -q # Display hardware system components - (SMBIOS/DMI)
hdparm -i /dev/hda List the architectural features of a disk
hdparm -tT /dev/sda Perform a test read on disk
cat /proc/cpuinfo Display CPU info
cat /proc/interrupts # display interrupt
cat /proc/meminfo Check memory usage
cat /proc/swaps Show which swap is used
cat /proc/version Display the version of the kernel
cat /proc/net/dev Display network adapters and statistics
cat /proc/mounts # display the loaded file system
lspci -tv # List PCI devices
lsusb -tv # Show USB device
date Display the system date
cal 2007 Display calendar for 2007The date is 041217002007.00# Set date and time - month, day, hour, year. seconds
clock -w Save time changes to BIOS
Copy the code
Shutdown (shutdown, reboot, and logout of the system)
shutdown -h now # Shutdown system
init 0 # Shutdown system
telinit 0 # Shutdown system
shutdown -h hours:minutes & Shut down the system at a predetermined time
shutdown -c Cancel shutting down the system at a scheduled time
shutdown -r now # to restart
reboot # to restart
logout # cancellation
Copy the code
Files and Directories
cd /home Enter the '/ home' directory
cd.# return to the previous directory
cd ../.. # return two levels of directories
cd Enter your home directory
cd ~user1 Enter your home directory
cd - # return the directory where you were last time
pwd # display the working path
ls View the files in the directory
ls -F View the files in the directory
ls -l Display file and directory details
ls -a # Show hidden files
ls *[0-9]* # Display the file name and directory name containing the number
tree Display the tree structure of files and directories starting from the root directory
lstree Display the tree structure of files and directories starting from the root directory
mkdir dir1 Create a directory called 'dir1'
mkdir dir1 dir2 Create two directories at once
mkdir -p /tmp/dir1/dir2 Create a directory tree
rm -f file1 # delete a file called 'file1'
rmdir dir1 # delete a directory called 'dir1'
rm -rf dir1 Delete a directory called 'dir1' and delete its contents at the same time
rm -rf dir1 dir2 Delete both directories and their contents
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 0712250000 file1 # Change the timestamp of a file or directory - (YYMMDDhhmm)
Copy the code
File search
find / -name file1 # enter the root file system from '/' to search for files and directories
find / -user user1 # search for files and directories belonging to user 'user1'
find /home/user1 -name \*.bin # search for files ending in'.bin' in 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 that have been created or modified in the last 10 days
find / -name \*.rpm -exec chmod 755 '{}' \; # Search for files ending in '.rpm' and define their permissions
find / -xdev -name \*.rpm # search for files ending in '.rpm', ignoring removable devices such as cd-rom drives and flash drives
locate \*.ps # find files ending in '.ps' - run 'updatedb' first
whereis halt Display the location of a binary, source, or man file
which halt Display the full path to a binary or executable file
Copy the code
Mount a file system
mount /dev/hda2 /mnt/hda2 # Mount a disk named hda2 - make sure the directory '/ MNT /hda2' already exists
umount /dev/hda2 # Unmount a disk called hda2 - exit from mount point '/ MNT /hda2'
fuser -km /mnt/hda2 # Force uninstallation when the device is busy
umount -n /mnt/hda2 Run the uninstall operation without writing to /etc/mtab - 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 CDROm or dvdrom
mount /dev/hdc /mnt/cdrecorder # Mount a CDRW or DVDROm
mount /dev/hdb /mnt/cdrecorder # Mount a CDRW or DVDROm
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 file system
mount /dev/sda1 /mnt/usbdisk Mount a USB flash drive or flash device
mount -t smbfs -o username=user,password=pass //WinClient/share /mnt/share Mount a Windows network share
Copy the code
Disk space
df -h Display a list of mounted partitions
ls -lSr |more Arrange files and directories by size
du -sh dir1 # estimate disk space used by directory 'dir1'
du -sk * | sort -rn Display file and directory sizes in order of capacity
rpm -q -a --qf '%10{SIZE}t%{NAME}n'| sort - k1, 1 n# display the space used by the installed RPM packages in order of size.
dpkg-query -W -f='${Installed-Size; 10}t${Package}n'| sort - k1, 1 n# show the size of the deb package installed (ubuntu, Debian)
Copy the code
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" group
useradd user1 Create a new user
userdel -r user1 # delete a user ('-r' excludes home directory)
usermod -c "User FTP" -g system -d /ftp/user1 -s /bin/nologin user1 # modify user attributes
passwd # change password
passwd user1 Alter user password (root only)
chage -E 2005-12-31 user1 Set the expiration period of the user passwordPWCK check'/etc/passwd' # file format and syntax fixes as well as existing usersGRPCK check'/etc/passwd' # file format and syntax fixes as well as existing groups
newgrp group_name # Log into a new group to change the default group of newly created files
Copy the code
File permission – Use “+” to set the permission and “-” to cancel it
Ls - lh show permissions ls/TMP | pr - T5 - W$COLUMNS Divide the terminal into 5 columns for display
chmod ugo+rwx directory1 Set owner (u), group (g), and other (o) permissions to read (r), write (w), and execute (x)
chmod go-rwx directory1 Delete group (g) and other (O) read/write execute permission on directory
chown user1 file1 # Change the owner attribute of a file
chown -R user1 directory1 # change the owner properties of a directory and change the properties of all files in the directory
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 files in a system that use SUID control
chmod u+s /bin/file1 Set the SUID bit of a binary file - the user running the file is given the same permissions as the owner
chmod u-s /bin/file1 # disable the SUID bit of a binary file
chmod g+s /home/public Set the SGID bit of a directory - similar to SUID, but specific to the directory
chmod g-s /home/public # Disable the SGID bit of a directory
chmod o+t /home/public # Set the STIKY bits of a file - only allow legal owners to delete files
chmod o-t /home/public # disable STIKY bits for a directory
Copy the code
Special properties of the file – Use “+” to set permissions and “-” to cancel
chattr +a file1 Only append files to read and write
chattr +c file1 # allow this file to be automatically compressed/uncompressed by the kernel
chattr +d file1 This file will be ignored by the dump program during a file system backup
chattr +i file1 Set to immutable files that cannot be deleted, modified, renamed, or linked
chattr +s file1 # Allow a file to be safely deleted
chattr +S file1 Once the application writes to the file, the system writes the changes to disk immediately
chattr +u file1 If the file is deleted, the system will allow you to restore the deleted file at a later time
lsattr Display special attributes
Copy the code
Package and compress files
Bunzip2 file1.bz2 unzip a file called'file1.bz2'The file bzip2 file1 is compressed with a file called'file1'Unzip the file gunzip file1.gz to a file called'file1.gz'The file gzip file1 is compressed with a file called'file1'Gzip-9 file1 maximum compression rar a file1.rar test_file creates a file called'file1.rar'Rar a file1. Rar file1 file2 dir1 Compressed simultaneously'file1'.'file2'As well as the directory'dir1'Tar -cvf archive.tar file1 Creates an uncompressed tarball. Tar -cvf archive.tar file1 file2 dir1 Creates an uncompressed tarball'file1'.'file2'As well as'dir1'Tar displays the contents of a package. Tar -xvf archive.tar Releases a package. Tar -xvf archive.tar -c/TMP Releases the compressed package to tar -cvfj in/TMP Archive.tar. bz2 dir1 Create a bzip2 package tar -jxvf archive.tar.bz2 Decompress a bzip2 package tar -cvfz archive.tar.gz dir1 Gz Decompress a gzip package. Zip file1.zip file1 Create a zip package. Zip -r file1.zip filee1 file2 Dir1 Compress several files and directories into a zip package. Unzip file1.zip Decompresses a ZIP packageCopy the code
RPM package – (Fedora, Redhat, and similar systems)
RPM Install an RPM package RPM -ivh --nodeeps package. RPM Install an RPM package and ignore dependency warnings RPM -u package. RPM Update an RPM package without changing its configuration file RPM -f package. RPM Updates an RPM package that has been installed-ePackage_name. RPM to remove an RPM package RPM - qa list all installed in the system of RPM package RPM - qa | grep HTTPD shows all name contains"httpd"RPM -qi package_name Obtain special information about an installed package RPM -qg"System Environment/Daemons"RPM -ql package_name Indicates the installed RPM package. RPM -qc package_name Indicates the installed RPM package. RPM -q package_name Indicates the installed RPM package --whatrequires Displays the list of dependencies with an RPM package RPM -q package_name -- WHATprovides Displays the volume occupied by an RPM package RPM -q package_name --scripts Display during the install/remove script execution by l package_name RPM - q - changelog show a RPM package revision history RPM - qf/etc/HTTPD/conf/HTTPD. Conf the confirmation to the documents provided by which RPM package RPM -qp package.rpm-lRPM --import /media/cdrom/RPM -gpg-key Import public KEY digital certificate RPM --checksig package. RPM Verify the integrity of an RPM package RPM -qa Gpg-pubkey Check the integrity of all installed RPM packages RPM -v package_name Check the file size, license, type, owner, group, MD5 check, and last modified time RPM -va Check all installed RPM packages in the system - Use RPM -vp with caution To identify a RPM package. The RPM package has not been installed rpm2cpio package. The RPM | cpio, extract, the make - bin directories * * from a RPM package run RPM - the ivh for executable files Rpmbuild --rebuild package_name.src. RPM Build an RPM package from an RPM sourceCopy the code
YUM Package Upgrader – (Fedora, RedHat and similar systems)
Install package_name yum localinstall package_name. RPM Yum update package_name yum update package_name yum update package_name yum remove Package_name Yum list Yum search package_name Yum search package_name Yum clean packages Yum clean packages Yum Clean All Deletes all cached packages and headersCopy the code
Viewing file Contents
Cat File1 Displays the contents of a file from the first byte forward. Tac File1 Displays the contents of a file from the last line in reverse. More File1 Displays the contents of a long file'more'Head-2 file1 Displays the tail of the first two lines of a file. Head-2 file1 displays the tail of the last two lines of a file-f /var/log/ Messages View the content added to a file in real timeCopy the code
Text processing
cat file1 | command( sed, grep, awk, grep, etc...) > result. TXT merge a text file detailed instructions, and to write introduction into a new file cat file1 |command( sed, grep, awk, grep, etc...) >> result.txt merges the detailed text of a file and writes the introduction to an existing file grep Aug /var/log/ messages in a file'/var/log/messages'Search keywords in"Aug"
grep ^Aug /var/log/ messages in a file'/var/log/messages'Look for to"Aug"The starting word grep [0-9] /var/log/ messages to choose'/var/log/messages'Grep Aug -r /var/ for all numeric lines in the filelog/ * in the directory'/var/log'And subsequent directories to search for strings"Aug"
sed 's/stringa1/stringa2/g'TXT file example. TXT"string1"replace"string2"
sed '/^$/d'TXT Remove all blank lines sed from example. TXT'/ *#/d; /^$/d'Example.txt Removes all comments and blank lines from example.txtecho 'esempio' | tr '[:lower:]' '[:upper:]'Merge the contents of the upper and lower cells sed-e '1d'Result. TXT excludes the first line sed-n from the file example. TXT'/stringa1/p'View only contained terms"string1"The line of sed-e 's/ *$//'Example.txt deletes the white space sed at the end of each line-e 's/stringa1//g'Example.txt removes only terms from the document"string1"And keep all the remaining sed-n'1, 5 p; 5q'Example. TXT displays sed-n from line 1 to line 5'5p; 5q'Example. TXT Look at line 5 sed-e 's/00*/0/g'More than example. TXT are replaced with a single zero zero cat cat - n file1 labeled file lines example. TXT | awk'NR%2==1'Delete all even lines in example.txtecho a b c | awk '{print $1}'Look at the first column of a rowecho a b c | awk '{print $1,$3}'Paste file1 File2 Combines the contents of two files or two columns-d '+'File1 File2 Combines the contents of two files or columns"+"To distinguish the sort file1 file2 sort the contents of two files sort file1 file2 | uniq took out two files and set (duplicate rows only keep a) sort file1 file2 | uniq - u delete the intersection, Leave other line sort file1 file2 | uniq-dExtract the intersection of two files (only the files that exist in both files are left) comm-1 file1 file2 Compares the contents of two files and deletes only'file1'Contents included comm-2 file1 file2 Compares the contents of two files and deletes only'file2'Contents comm-3 file1 file2 Compares the contents of two files and deletes only the common parts of the two filesCopy the code
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 two swap partitionsCopy the code
The backup
dump -0aj -f/ TMP /home0.bak /home'/home'Full backup of directory dump-1aj-f/ TMP /home0.bak /home'/home'Back Restore an interactive backup rsync-rogpav --delete /home/tmp synchronize the directory rsync-rogpav on both sides-eSSH --delete /home/ip_address :/ TMP Through the SSH channel rsync rsync-az-e ssh --delete ip_addr:/home/public /home/localSynchronize a remote directory to the local directory rsync-az using SSH and compression-e ssh --delete /home/localIp_addr :/home/public Synchronize the local directory to the remote directory through SSH and compression dd bs=1Mif=/dev/hda | gzip | ssh user@ip_addr 'dd of=hda.gz'Back up the local disk dd on the remote host over SSHif=/dev/sda of=/ TMP /file1 Backs up disk contents to a file tar -puf backup.tar /home/user Performs a pair of files once'/home/user'Interactive backup operations for directories (cd /tmp/local/ && tar c . ) | ssh -C user@ip_addr 'cd /home/share/ && tar x -p'Via SSH to copy a directory content in the remote directory (tar c/home) | SSH user @ ip_addr - c'cd /home/backup-home && tar x -p'Via SSH in the remote directory copy a local directory tar cf -. | (cd/tmp/backup ; Tar xf -) locally copy a directory to another location with original permissions and link find /home/user1-name'*.txt'| xargs cp - av -- target - directory = / home/backup / -- parents from a directory to find and copy for all'.txt'The ending file goes to another directory find /var/log -name '*.log'| tar CV - files - from = - | bzip2 > the tar. Search for all the.bz2'.log'End the file and make a Bzip package ddif=/dev/hda of=/dev/fd0 bs=512 count=1 Copy the contents of the MBR (Master Boot Record) to the floppy disk ddif=/dev/fd0 of=/dev/hda bs=512 count=1 Restore the MBR content from the backup saved to the floppy diskCopy the code