13.A symbolic link (also referred to as soft link) does not link directly to the inode but to the name of the file,symbolic links is that they can link to files on other devices, as well as on directories 14. hard link --> inode --> datablocks sombolic link --> hard link --> inode --> datablocks 15.to create hard links, you must be the owner of the item that you want to link to. This is a new security restriction that has been introduced in RHEL 7 16.tar -cvf archivename.tar /files-you-want-to-archive tar -rvf /root/homes.tar /etc/hosts #add the /etc/hosts file to the archive tar -uvf /root/homes.tar /home #write newer versions of all files in /home to the archive. tar -tvf /root/homes.tar #ee the contents of the tar archive tar -xvf homes.tar -C /tmp tar -xvf /archivename.tar /file-you-want-to-extract tar -xvf /root/etc.tar /etc/hosts #archive etc.tar contains the file /etc/hosts that you want to extract 17.gzip or bzip2 -z (gzip) or -j (bzip2) Options: c Creates an archive. v Shows verbose output while tar is working. f Used to specify the name of the tar archive that is to be used. Without using this option, the default destination is STDIN for -x and STDOUT for -c . t Shows the contents of an archive. z Compresses/decompresses the archive while creating it, by using gzip. j Compresses/decompresses the archive by using bzip2. x Extracts an archive. u Updates an archive; only newer files will be written to the archive. C Changes the working directory before performing the command. r Appends files to an archive. *************************************************************************************************************** 1.vim and man :That is because all of these commands are based on the same code 2.tail -n 5 /etc/passwd(tail -5 /etc/passwd) tail -f /var/log/messages #n real-time messages that are written to the main log file /var/log/messages 3.head -11 /etc/passwd |tail -n 1 #see line number 11 of the /etc/passwd file head -n 5 /etc/passwd #show the first five lines in /etc/passwd tail -n 2 /etc/passwd #show the last two lines of /etc/passwd 4.cut -d option to specify the field delimiter followed by -f with the number of the specific field you want to filter out cut -f1 -d: /etc/passwd 5. cut -f1 -d: /etc/passwd |sort #sorts the contents of the first column in the /etc/passwd file 6.sort :By default, the sort command sorts in alphabetic order. cut -f2 -d: /etc/passwd | sort -n #sort the second field of the /etc/passwd file in numeric order du -h | sort -rn #get a list of files sorted with the biggest file in that directory listed first sort -k3 -n -t: /etc/passwd #不能缺少-n选项 ps aux |sort -k3 -n
7. wc file :the number of lines, the number of words, and the number of characters. 8.grep grep anna /etc/passwd grep ^anna /etc/passwd begin with the text anna grep ash$ /etc/passwd end with the text ash . ************************************************************************* prevent the regular expression from being interpreted by the shell grep '^anna' /etc/passwd ************************************************************************* 9.Regular Expression ^text Line starts with text. text$ Line ends with text. . Wildcard. (Matches any single character.) [abc] Matches a, b, or c. * Match 0 to an infinite number of the previous character. \{2\} Match exactly 2 of the previous character. \{1,3\} Match a minimum of 1 and a maximum of 3 of the previous character. colou?r Match 0 or 1 of the previous character. This makes the previous character optional,which in this example would match both color and colour . "/web(/.*)?":the regular expression (/.*)?, which means zero or one (/.*) 10.grep(general regular expression parser): -i Not case sensitive. Matches uppercase as well as lowercase. -v Only show lines that do not contain the regular expression. -r Search files in the current directory and all subdirectories. -e Use this to search for lines matching more than one regular expression. -A <number> Show <number> of lines after the matching regular expression. -B <number> Show <number> of lines before the matching regular expression.
grep '^#' /etc/sysconfig/sshd grep -v '^#' /etc/sysconfig/sshd grep -v '^#' /etc/sysconfig/sshd -B 5 grep -v -e '^#' /etc/sysconfig/sshd 11.awk and sed: awk -F: '{print $4}' /etc/passwd #shows the fourth line from /etc/passwd awk -F: '/user/ {print $4}' /etc/passwd #searches the /etc/passwd file for the text user and will print the fourth field of any matching line sed -n 5p /etc/passwd #print the fifth line from the /etc/passwd file sed -i s/old-text/new-test/g ~/myfile #-i will write the result directly to the file sed -i -e '2d' ~/myfile #you can delete a line based on a specific line number sed -i -e '2d;20,25d' ~/myfile #delete lines 2 and 20 through 25 in the file ~/myfile.