Device name, common directory
IDE hard disk # device name -- -- -- -- -- -- -- -- -- -- / dev/hd/a - d SCSI/SATA/USB hard drive -- -- -- -- -- -- -- / dev/sd/a - p drive -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- / dev/cdrom or/dev/HDC Floppy disk -- -- -- -- -- -- -- -- -- -- / dev/fd [0, 1] printer needle (25) -- -- -- -- -- -- -- - / dev/lp [0-2] printer (USB) -- -- -- -- -- -- -- -- -- -- - / dev/USB/lp [15] 0 - mouse -- -- -- -- -- -- -- a common directory - # / dev/mouse / root - /boot Boot directory, - /dev device file - /etc configuration file - /home Home directory for common users, which can be operated - /lib directory for saving system libraries - / MNT directory for mounting mobile devices - /media directory for mounting cd-rom - /misc directory for mounting tape drives - /root home directory of superuser - / TMP temporary directory - /proc Memory mount point - /sys - /var variable - /bin Common command - /sbin command save directory, - /usr/bin System software resource directory System commands for common users - /usr/sbin System software resource directory System commands for super usersCopy the code
Basic commands
Chmod u+r g+w o+x + ln -s /etc/nginx ~/nginx Locate a.t # locate a.t # locate a file whose id number is located in k units TXT find. -iname lrj.txt find. -user root find -atime +5 access 5 days ago find. -ctime -5 change 5 days ago find. -mtime 5 modify current find. -size 100K File find/TMP -size +10k -a -size -20k -exec ls -lh {} \; -name search file name -size file size -iname ignore case -a and -o perform operations on the result of the previous command with files larger than 10KB and smaller than 20KB in the or /etc directoryCopy the code
# filter search (ignore case, Excluded from one text) cat a.t xt | grep - iv one # modified files belonging to the user chown LRJ a.t xt # shutdown - shutdown -r 22:00 at 22:00 restart - shutdown - h Copy a. TXT b. TXT -p Copy Folder folder1 -rCopy the code
Compression decompression
Zip => gzip => bz2 The later the compression format, the higher the compression ratio. Zip 1.zip 1.txt unzip 1.zip -r book.zip book(is a folder) unzip book.zip zip advantages: Can compress folders, the compression ratio is not as good as the other two #gzip Gzip -c 1.txt > 1.txt. Gz gzip -d 1.txt. Gz gzip -c 1.txt > 1.txt. When you compress a folder, gzip -r compresses all the files in the folder. # bzip2 usage: Bzip2 1.txt bzip2 -d 1.txt.bz2 cannot compress the folder # pack tar-cvf 1.tar folder tar-xvf 1.tar # Add the tar-zcvf 1.tar.gz folder Bz2 Folder bzip2 tart -jxvf 1.tar.bz2 Folder bzip2 tart -jxvf 1.tar.bz2 folder bzip2 tart -jxvf 1.tar.bz2 folder bzip2Copy the code
Partition memory
TMPFS df -x TMPFS # check the size of all files in the current directory du -h # check the size of all files in the current directory du -h According to the result of human can read sorting, r reverse du - hd 1. | sort - hr # to check the hard disk partition situation fisk - l # fdisk SDB to hard disk partition/dev/SDB and then input n create new partitions, partition number is specified, the starting end of the cylinder, the final w, If you want to create an extended partition, you must create a logical partition. The logical partition number starts with 5, also enter n. After you create a logical partition, Ext3 /dev/sdb1 MKFS -t ext4 /dev/sdb2 # Mount partition mount /dev/sdb1 / MNT /u1 # Unmount partition umount/MNT /u1 /etc/fstab file is the file that records the partition mount information. Fdisk /dev/sdb Enter t to change the partition number and enter the new PARTITION ID (the swap value is 82, and the common Linux partition value is 83). Step 2 Format the partition mkswap /dev/sdb2 Step 3: Swapon /dev/sdb2 Mount the partition to the swap partition eg: Mount the CD/DVD-ROM drive. To create a directory, mount /dev/sr0 / MNT /cdrom to the MBR partition format. A maximum of four MBR partitions are supported. You can create multiple partitions under the extended partition. GPT new partition format, no upper limit. parted select /dev/sdc mklabel gpt mkpartCopy the code
User groups
/etc/group # name of the group: password placeholder: group number: list of user names in the group (null indicates the same user name as the group name) /etc/gshadow # Name of the group, password placeholder (* is null), group manager, empty indicates that the group manager can manage the group. /etc/passwd # user name, password placeholder, user group number, user comment information, user home directory, Shell type /etc/shadow # password information of all users # whoami # ID of user root # Groups root # groupadd stu Groupdel 222(group id) groupmod -n student stu # useradd -g teacher jack useradd -d /home/jack jack usermod -g jack Root userdel jack # change password passwd jack # switch user su user nameCopy the code
vim
A #after insert I #insert o #other insert s # replace the letter where the cursor is insert :2 # line /jie # search? Jie # Search forward from cursor position n/N # Next next LKJH # Right upper lower Left CTRL + F # Scroll down CTRL + B # Scroll up CTRL + D # Scroll down half page CTRL + U # Scroll up half page DD # Delete YY # Copy P # Paste X # Delete a dw delete a de delete to end d$Delete to end of line U # Cancel ZZ # Save exit select any text CTRL v d y p # Global replace :%s/old/new/g # Replace lines 2-5 :2,5s/old/new/gCopy the code
permissions
Chmod xyz modify object: Chmod [ugoa]+/-[RWX] For a folder, r indicates that the folder can be ls, w indicates that the folder can be modified, deleted, or added to its subdirectories (but x permission is required for subfiles or folders). X means CD can go in notice; Without the W permission for a folder, you can still modify the contents of the files in that folder. You just can't change the directory structure under that folder (i.e., subfolders, subfiles, -chown zf1 folder -chown root:root folder -chgrp zf1 folder - The default permission for creating a file is 666. The default permission for creating a folder is 777, but the rules for subtracting the value of umask are as follows: umask 022 (000 010 010) On the basis of 666, the write permission of the owning group and others is subtracted. Temporary change umask Yes Umask 044 Permanent change /etc/profileCopy the code
ACL
Dumpe2fs -h /dev/sda1 check whether the command output contains an ACL. Default mount options Temporarily enable the ACL permission for the partition. Mount -o remount,acl /dev/sda1 Vi /etc/fstab UUID/ext4 defaults, ACL 1 1 mount -o remount /dev/sda1 ACL There's a teacher in the student group, and the teacher's home directory is 7, and the student group is 7, but what happens when another user, like the ta, comes in and wants him to read and write? If you put it in the student group, then you have x permissions. Put into others is more pit, became in addition to the teacher all users. Setfacl -m u:guest:rw Folder # Set group ACL permissions (add -r to set same ACL permissions for subfiles) Setfacl -m g:guest:rw folder # Delete acl permission setfacl -x g:guest Folder # Check acl information of folders getfacl folder # Set mask value setfacl -m m:rw Folder (must be set after the ACL permission is set, otherwise it will be overwritten by the default mask) Acl also has mask rules, we set acl permission, will match the value of mask, the final result, is the final permission, mask is actually although I allow ACL permission, but, Mask :rw- # Delete all ACL permissions setfacl -b folder # Default ACL permissions Setfacl -m d:u:someone:rw Folder # Delete default permissions setfacl -k folder eg: useradd guest mkdir /home/guest/folder useradd teacher groupadd students mkdir folder chown teacher:students Setfacl -m U :guest:rw Folder Check the getFacl folder sudo some commands are system commands. Root ALL =(ALL) ALL username Managed host address =(Available identity) Authorization command (absolute path) Allow LRJ, On IP 127, run the useradd command LRJ 127.0.0.1=(root) /usr/sbin/useradd as root.Copy the code
shell
History records when you log in, log out, All the history commands -c clear the history commands -w Write the history commands in the cache to the history command file ~/. Bash_history 1000 history commands are saved by default /etc/profile HISSIZE=10000 Redirection echo hello > a.txt standard output Echo hello >> a.txt append write > Can only redirect stdout, cannot redirect stDOut, Log 2>&1 cat xxx. TXT 2>err.log echo right && cat xx > normal.log 2>err.log Enter redirection WC -l < Single quotes: pure string processing double quotes: $' \ have special meaning, other as single quotes $(), backquotes: $, #, \ fetch variable value, comment, escape set check all variables in the system, including custom, Set -u User - defined environment variable export variable name = Variable value View the process tree pstree Enter the child bash common environment variables - $1 2345... For I in "$@" (for I in "$*") do echo $I done $? Did the last command executed succeed or fail? Zero success is not zero failure? The id of the current process $! If you run the script sh xxx.sh & in the background, it will return a process id echo $! Interactive read-p 'num1 read-p' num2 echo $((num1+num2)) -t 10 Exit after 10 seconds -s When entering password Echo -e '\n' : echo -e '\n' : echo -e '\n' $(()) $[] $(expr $num + $num2) $(expr $num + $num2) Declare -i age declare -x NAME=zhufeng Declare -r x declare -a names[0]= ZHANGsan Names [1]=lisi echo ${names[*]} Environment variables Run: /etc/profile ----------- Umask, USER, HOSTNAE, execute all sh ~/.bash_profile ----------- in profile.d to modify the PATH. Bashrc ~/. Bashrc -------- Call /etc/bashrc /etc/bashrc --------PS1 login prompt modify here, umask, PATH variable, call /etc/profile.d/star.sh file source.bash_profile is equivalent to.. TXT --color=auto: /etc/bashrc regular correlation ls /etc/1.t* grep "^li" 1. TXT --color=auto: Separator, the extraction of the first and second column cat/etc/passwd | the cut - f 1, 2 - d: Printf can format output (because df -h delimiters are not fixed, there are Spaces and tabs, printf can dispose of them, For separated with \ t) printf (" % s \ \ t t % s % s \ \ t t % s % s \ \ t t % s \ n ") $(df -h | grep/dev/sda1) | the cut - f 5 | the cut - d % awk 'condition 1 action {1} {2} action 2... 'File name $0 full line $1 first column... Df -h | grep/dev/sda3 | awk '{print $5}' number. TXT in three lines of text, respectively is 1 a line, a line 2, 3 a line, awk like printf, Awk '{BEGIN{num=0}{num=num+$1}END{print num}}' number. TXT Specifies the delimiter awk 'BEGIN{FS=":"}{print $1,$2}' /etc/passwd With conditions of demo awk '$1 > 90 {print $1 "\ t" excellent} $2 < 90 {print $2 "\ t pass the exam"}' score. TXT condition judgment judgment can be read to write executable [- r number. TXT] && echo 'yse' | | echo 'no' [ -w number.txt ] && echo 'yse' || echo 'no' [ -x number.txt ] && echo 'yse' || echo 'no' [ -e number.txt ] && echo 'yse' || echo 'no' [ -d number.txt ] && echo 'yse' || echo 'no' [ -f number.txt ] && echo 'yse' || echo 'no' Whether files older than/newer than/hard links [write. TXT - nt read. TXT] && echo "write is older than the read" | | echo "no" [read. TXT - ot write.txt ]&&echo "read is older than write"|| echo "no" ln execute.txt execute2.txt [ execute.txt -ef execute2.txt ] && echo the execute and execute2. TXT "are the same" | | echo whether "no" to judge whether the string is empty name = lirnejie [z] "$name" && echo "yes" | | echo "No" to determine whether a string is not empty name2 = lirnejie [" $name "= =" $name2 "] && echo "yes" | | echo "no" pit shell must leave Spaces around in this [] -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- logic with [2-1 gt 2-3 - a gt] && echo "yes" | | echo "no" logic or [1 - o 3-2 - gt gt 4] && echo "yes" | | echo "no" logic of [! 3 -gt 4 ]&&echo "yes"|| echo "no" -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- if [conditions determine 1) then Body 1 elIF [condition judgment 2] body 2 else body 3 FI -------------------------------------------------------------------------------------------------------- read -p "yes or no?" -t 30 choose case $choose in "yes") echo 'yes' ;; "no") echo "no" ;; *) echo other ;; Esac -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- in the for variables Value 1 value 2 value 3 do done while conditional judgment -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- the function can be omitted, Sum4 (){r=$(($1+$2)) return $r} sum4 2 3 echo $?Copy the code
Installation of software packages
2. Yum install yum list yum install yum remove yum update The yum configuration file is in /etc, and you can check the yum configuration information. Source installation install GCC compiler yum install GCC wget https://npm.taobao.org/mirrors/node/v10.15.3/node-v10.15.3.tar.gz to download the source code extract solution package /configure --prefix=/usr/local/node/10.15.3 Make make install makefile will be generatedCopy the code
Service
System Running level 0 Shutdown 1 Single-user, window-like safe mode, mainly used for system repair 2 Incomplete multi-user, similar to character interface, but does not include NFS(Linux and Windows for file sharing) service 3 Complete command line mode, 4 system reserved unused 5 GUI 6 Restart check the computer process ps-aux check the listening network port netstat-tulnp list TCP data/list UDP data (native) Linux services will be in /etc/init.d/ # Service XXX is an extension of centos 6. Service iptables Status Stopping the firewall service iptables stop Starting the firewall service iptables start Restarting the firewall service Iptables restart Disabling the firewall permanently chkconfig iptables off Enabling the firewall permanently chkconfig iptables on Checking the firewall status service iptables status Since the launch service (all distribution to support the chkconfig) the chkconfig -- list | grep nginx nginx powered up for the chkconfig -- level 2345 nginx on boot off start nginx chkconfig Nginx off -- Cenos7 Systemctl list-unit-files Add systemctl enable nginx Disable systemctl disable nginx View the status of the systemctl service status iptables.service; Stop a service systemctl stop firewalld.service; /etc/rc.d/rc.local is used to run the /etc/rc.local command or add chkconfig --add nginx command before loginCopy the code
Process system
# view all processes in the system, use BSD operating system format ps-aux # view all processes in the system, use Linux standard format ps-le # view (including operating system related) top will continue to execute, so as to refresh the latest situation, use -n 3 to specify the number of execution, -b Displays the information about the first task queue in batch mode, including the current system time, the system has been running for x days x hours XX minutes, two clients have been logged in, and the system load averages of the previous 1 minute, 5 minutes, and 15 minutes. It is generally considered that a load less than 1 hour is small, and a load greater than 1 exceeds the second behavior of the load process information - the total number of processes in the system, the number of running processes, sleeping processes, stopping processes, zombie processes. If not 0, check the third behavior CPU information CPU (s): 0.1% US CPU usage in user mode 0.1% SY CPU usage in system mode 0.0% NI CPU usage of user processes whose priorities have changed 99.7% ID CPU usage of idle CPU 0.1% WA CPU usage of processes waiting for input/output 0.1% HI CPU used by hard interrupt request services 0.1% SI CPU used by soft interrupt request services 0.0% ST Steal Time (ST) Virtual time percentage, 1. This signal will cause the process to shut down immediately, and then rewrite the configuration file and restart the process. 2. This signal can not be blocked, processed, or ignored. It is generally used to forcibly terminate the process. 9. If we don't abort normally, This is not running nice-n-5 service HTTPD start this is already running renice-10 pid #jobs Jobs -l is used to view all jobs. The first column is the job id. Fg Job id. Put the job in the foreground. /etc/rc.local # /etc/rc.local # /etc/rc.local # /etc/rc.local Procs r Indicates the number of processes waiting to run. The larger the number, the busier the system will be. Procs B Indicates the number of processes that cannot be awakened. System is busy - h # # memory free view which process calls a file was lsof/usr/local/nginx/sbin/nginx # check what documents lsof - a process called c # nginx query a user invokes the which files lsof -u Atrm Delete scheduled tasks from the whitelist of the AT command /etc/at.allow Disable the black order /etc/at.deny of the AT command (If the whitelist exists, black is ignored.) Crontab -e Enters editing mode. {daily,weekly,monthly} /etc/anacrontab # /etc/anacrontab The configuration file for the computer SHELL = / bin/sh PATH = / sbin/bin: / usr/sbin, / usr/bin MAILTO = root # maximum random delay time (minutes) RANDOM_DELAY=45 # Anacron execution time range is 3:00 ~ 22:00 START_HOURS_RANGE=3-22 Execution force delay every few days (minutes) Modify priority execute all scripts under directory 1 5 cron.daily nice run-parts /etc/cron.daily 7 25 cron.weekly nice run-parts /etc/cron.weekly @monthly 45 cron.monthly nice run-parts /etc/cron.monthlyCopy the code
network
-ifdown eth0 -ifup eth0 start network service Start network service Temporarily set the IP address and subnet mask for eth0 Ifconfig eth0 172.18.0.254 netmask 255.355.255.0 # setup permanent configuration IP setup service network restart / etc/sysconfig/network - scripts/ifcfg - eth0 TYPE = Ethernet -- -- -- -- -- -- -- -- -- -- -- -- # card TYPE DEVICE = eth0 -- -- -- -- -- -- -- -- -- -- -- -- # network card interface name ONBOOT = yes -- -- -- -- -- -- -- -- -- -- - # system startup is automatically loaded BOOTPROTO = static -- -- -- -- -- -- -- -- -- -- -- -- # enable address protocol -- static: static agreement - the bootp protocol - DHCP protocol IPADDR = 192.168.1.11 -- -- -- -- -- -- -- -- -- -- -- -- -- # network card IP address NETMASK = 255.255.255.0 -- -- -- -- -- -- -- -- -- -- # card network address < GATEWAY = 192.168.1.1 -- -- -- -- -- -- -- -- -- -- # network GATEWAY address DNS1 = 10.203.104.41 -- -- -- -- -- -- -- -- -- # nic DNS address HWADDR = 00:0 C: : this 5 d: # 74 -- -- -- -- -- -- -- -- network card MAC address equipment BROADCAST=192.168.1.255------------# nic BROADCAST address # /etc/sysconfig/network NETWORKING=yes Whether the network function works HOSTNAME=localhost. Localdomain HOSTNAME XXX service network restart # cat /etc/resolv.conf nameserver 8.8.8.8 DNS server Search localhost nameserver 8.8.8.8 # netstat ltunp -> listen TCP UDP Uses IP address and port number process instead of domain name and service nameCopy the code