Wildcard characters for file names:
[0-9]\[a-z]\[[:d Igit:]]\[[:alpha:]]\[[:alnum]]\[[:upper:]]\[[:lower:]]\[[:black:]]
Rename renaming
# Rename. txt. xsl/app
Tree
View Structure-d-l
Tr
# ifconfig eth0 |tr A-Z A->ip.txt you can save by converting and exporting first
# echo ' ERROR!!! ' |tr A-Z >error.txt 1>&2 The correct output is 1. The error is 2, this is the correct conversion to the wrong output, the correct output error!!! has been imported into the error.txt, so should not be shown, but now it is shown because the correct turn into the wrong output
DF Disk
Mail email
# mail "hi" |mail-s "Hello" [email protected]
Tee can save a copy of the command
# echo Hello |tee/app/test.txt |tr A-Z
redirect
# TR A-Z </etc/issue >/tmp/issue.out
Do a question.
1 to 100 of the and
# echo {1..100} |tr "" "+" |BC BC for arithmetic
Chage
Chage-l user1 query password chage user1 interactive settings policy-D YYYY-MM-DD Specify the last modified time of password-e yyyy-mm-dd Set password expiration time I days password expires how many days after account expires-m days password minimum survival period---days secret Code maximum survival period----days before password expiration remind users
Useradd Query ID +username
-u Specifies uid-g specifies gid-c Note-d specifies that the home directory first has a parent directory, the home directory does not exist
gpasswd
GroupName set password to group-a user group Add users to additional group-D user group kicks users out of the group
Umask Erase what permissions
When Umask is 002, as explained by default permissions, directory is 777, file is 666 then when you create directory, you subtract 002, that is, 775 rwxrwxr-x create file, it will subtract 002, that is 664 rw-rw-r--directly modify Umask umask 064umask But when there is an odd number, there must be X, the directory permission is even, subtract, you have to add 1
1. TR Conversion and deletion
-S will repeat the word and tr-s [[: Blank:]]: A plurality of space synthesis of one, converted to ': ' Old iron, blank without line break, space with newline-D Delete the selection tr-d [a-za-z]
2, head to take the first
-N gets how many lines before-C gets the number of characters before
3, tail take the tail
-F Displays new additions and is used for monitoring logs
4. Cut Extraction
-d Specifies what the delimiter is cut-d: The colon is the delimiter, multi-mate-F uses-F to take the first few fields-F 2, 5, take 2 and 5-f 2-5, take 2 to 5-c by character cut cut-c 1-4/etc/passwd take pas SWD top four characters
5, the WC collects the text statistic data
WC equals-l-w-c All-l count rows-W count words-C count bytes-m number of characters
6. Sort order
-n Sort by digit-R reverse-F option ignore (fold) the character case in string-u option (unique, uniquely) delete duplicate lines in output-T C with C as field qualifier Sort-t:/etc/passwd mate-k-k N in nth field after C Row sort
7, Uniq to Heavy
Uniq-c: Displays the number of occurrences of each row-D: Show only repeated rows-u: Show only rows that have not been repeated and are identical to duplicate
8. grep Search
GREP=GREP--COLOR-V displays lines that are not matched grep-v Root/etc/passwd-i: Ignores character case grep-i root/etc/passwd-n: Displays matching line numbers grep-n Root/etc/passwd-c: Statistics match the number of rows grep-c Root/etc/passwd-o: Show only the matched string Grep-o root/etc/passwd-q: Silent mode, do not output any information grep -Q root/etc/passwd >/app/123.txt-a #: After, # line grep-2 Root/etc/passwd-b #: Before, front # line Grep-2 root/etc/passwd-c #:context, front and back # lines Grep-2 ROOT/ETC/PASSWD-E: Implementing a logical or relationship between multiple options grep–e ' root '-e ' Guanjunhou '/etc/passwd-w: matches the entire word grep-w ROOT/ETC/PASSWD-E: Using ere-f: Equivalent to Fgrep, regular expressions are not supported
9, character matching, wildcard characters (symbol matching a large ~)
. matches any single character [] matches any single character in the specified range [^] matches any single character outside the specified range [: Alnum:] Letters and Numbers [: Alpha:] represents any English uppercase and lowercase characters, i.e. A-Z, A-Z [: Lower:] lowercase [: upp ER:] uppercase [: blank:] white space characters (spaces and tabs) [: space:] horizontal and vertical whitespace characters (wider than [: blank:]) [: Cntrl:] non-printable control characters (backspace, delete, alarm ...) ) [:d igit:] decimal digit [: xdigit:] Hexadecimal number [: graph:] printable non-whitespace character [:p rint:] printable character [:p unct:] Punctuation
Number of Matches
* match the preceding characters any time, including 0 greedy modes: match grep root* as long as possible. * Any character of any length? Matches the preceding character 0 or 1 times \+ matches its preceding character at least 1 times \{n\} matches the preceding character n times \{m,n\} matches the preceding character at least m times, up to n times \{,n\} matches the preceding character up to n Times \{n,\} matches the preceding character at least n times
Position anchoring: positioning where it appears
^ line anchor, used for the leftmost $ end anchor of the pattern, the rightmost ^pattern$ of the pattern used for pattern matching entire row ^$ blank line ^[[:space:]]*$ blank line \< or \b Word anchor, used for Word mode left \> or \b Ending anchor; the right side of the word pattern \<pattern\> matches the entire word
Exercises:
* 1, find ifconfig "NIC name" command results in the IPV4 address of the machine
# ifconfig eth0 |head-2 |tail-1 |cut-d:-f2 |cut-d ""-f1
* 2, the maximum percentage of partition space utilization is detected
#df-H |tr-s ""% |cut-d%-f5 |sort-nr |head-1
* 3, identify the user UID maximum user name, UID and shell type
# cat/etc/passwd |cut-d:-f1,3,7 |sort-t:-k2-n |tail-1
* 4, to detect the permissions of/tmp, digital display
# Stat/tmp | Head-4 |tail-1 | Cut-d ' ('-F 2 | cut-d '/'-F 1
# stat-c%a/tmp/
* 5. Count the number of connections for each remote host IP that is currently connected to this machine, and press from large to small
# Netstat-nt | Tr-s ' | cut-d "-f5 |grep-v" Add\|server "|cut-d:-f1 |sort |uniq-c
Exercises: Head tail cat cut1, find the Ifconfig "NIC name" command results in the IPV4 address 2, the maximum percentage of partition space utilization of the value 3, identify the user UID maximum value of the user name, UID and Shell type 4, the right to detect/tmp, Display digitally 5, count the number of connections to each remote host IP currently connected to the machine, and sort from large to small
# ifconfig eth0 |head-2|tail-1|cut-d:-f2|tr-d [a-za-z]
# DF |tr-s "": |cut-d:-f5|head-2|tail-1
# cat/etc/passwd |sort-nt:-k3|tail-1|cut-d:-f1,3,7
# stat/tmp|head-4|tail-1|cut-d ' ('-f2 |cut-d '/'-F1
# netstat-nt |tr-s ': |sort-nrt:-k3|head-1|cut-d:-f5
Exercises: grep
1, display the/proc/meminfo file in the beginning of the size of the line (requires: use two methods) 2, the/etc/passwd file does not end with the/bin/bash Line 3, display the user RPC default shell program 4, find out/etc/ passwd two-bit or three-digit 5, in the/etc/grub2.cfg file that displays CentOS7, with at least one white-space character, followed by line 6 with non-whitespace characters, finding the result of the "Netstat-tan" command with ' LISTEN ' followed by any number of Line 7 at the end of a whitespace character, display the user name and UID8 of all system users on CentOS7, add User bash, Testbash, basher, SH, nologin (whose shell is/sbin/nologin), find out/etc/ passwd user name with Shell name Line
# grep "^[ss]"/proc/meminfo# grep-i "^s"/proc/meminfo# grep "^s\|^s"/proc/meminfo# grep-e ^s-e ^s/proc/meminfo
# grep-v "/bin/bash$"/etc/passwd
# grep "^rpc\>" etc/passwd |cut-d:-f7
# grep "[[:d igit:]]\{2,3\}"/etc/passwd
# cat grub.conf |grep "^[[:space:]]\+[^[:space:]
# Netstat-tan |grep "listen[[:space:]]\+"
# CAT/ETC/PASSWD | Cut-d ': '-F 1,3 | grep "\<[1-4]\?" [0-9]\? [0-9]\> "
# cat/etc/passwd |grep "\ (^.*\) \>.*\<\1$" # cat/etc/passwd |egrep "(^.*) \>.*/\1$"
Exercises:
1. linux file permissions are 10 bits in length, divided into four segments, the third paragraph indicates: C
A file type B file owner's permissions C file owner group permissions D other users ' permissions # stat/app/123.txt (-rw-r--r--)
2. A file name is RR. Z, the command that can be used to decompress is: C
A tar B gzip C compress D uncompress
3. There are four ways to assign variables in the shell, where the Name=12 method is called: a
A Direct Assignment b using the Read command C using command line arguments D using the output of the command
4. Which command can intercept data from each line of a text file for the specified content: D
A CP B DD C FMT D cut # cut-d:-f7/etc/passwd
5. Linux has three commands to view files, if you want to view the contents of the file can be moved up and down to view the contents of the file, which command should be used: C
A Cat B More C less D menu # cat\|more\|less etc/passwd
6. A file named Fido has been modified with chmod 551 Fido, and its permission is: D
A-rwxr-xr-x B-rwxr–r–c-r–r–r–d-r-xr-x--x-r-xr-x--x (rwx=421)
7. Use the Ls–al command to list the file listed below, which is the symbolic connection file: D
A-rw-rw-rw-2 hel-s users, Sep 11:05 Hello b-rwxrwxrwx 2 hel-s users, Sep 11:05 goodbey C drwxr–r–1 hel users Sep 08:10 zhangd lrwxr–r–1 hel users 2024 Sep 08:12 Cheng Soft connect front with L, index or 1, hard link index +1
8. When you restart the Linux system and write the information in memory to the hard disk, which command should be used to implement: D
A # reboot B # halt C # init 3 D # Shutdown–r now
9. Which command can be used to turn off the Linux system (without restarting): B
A Ctrl Alt Del B halt C shutdown-r now D reboot
10. In the vi Editor, in command mode, type which one can add a new line under the current line of the cursor: B
a〈a〉; b〈o〉; c〈i〉; D A
11. In the vi Editor, in command mode, delete the command that is used at the current cursor: A
a〈x〉; b〈d〉;〈w〉; c〈d〉; d〈d〉;〈d〉;
12. In the vi Editor, in command mode, repeat the last action on the edited text, which command you can use: C
A up ARROW B down arrow c〈.〉; d〈*〉;
13. The description of the file FF is shown in the command ls-al as follows, so the type of file FF is: A
-rwxr-xr–1 root root 599 Cec 17:12 ff A plain file B hard link C directory D symbolic Link (-normal file D directory L "lowercase l" connection)
14. The Delete file command is: D
A mkdir B rmdir C MV D RM
15 The command to archive the file is: D
A DD B cpio C gzip D tar
16. The command to change the file owner is: C
A chmod B Touch C chown D Cat
17. The command to find a string in the given file that matches the set criteria is: A
A grep B gzip C Find D sort
18. To create a new empty file, you can use the following command: D
A chmod B more C CP D touch
19. In the following command, the command that cannot display the contents of a text file is: D
A more B less C tail D join
20. Set Superuser root current directory is:/usr/local, after you type the CD command, the user's current directory is: B
A/home b/root C/home/root d/usr/local
21. The command to install the CD-ROM (hdc) to the/mnt/cdrom directory of the file system is: C
A mount/mnt/cdrom B mount/mnt/cdrom/dev/hdc C mount/dev/hdc/mnt/cdrom D MOUNT/DEV/HDC
22. The command to unmount the disc/DEV/HDC is: a
A umount/dev/hdc B unmount/dev/hdc C umount/mnt/cdrom/dev/hdc D UNMOUNT/MNT/CDROM/DEV/HDC
23. There is a file in the/home/stud1/wang directory, which executes the command in the background using one of the following implementations, which outputs the contents of the file to the File.Copy file: C
A cat file〉;file.copy B cat〉;file.copy C cat file > File.Copy & D Cat File〉;file.copy &
This article from "13277682" blog, declined reprint!
Linux Lesson Two