1. Display lines starting with size s in the/proc/meminfo file (required: use two methods)
# Cat/proc/meminfo | Grep-i ' ^s '
# grep ' ^[ss] '/proc/meminfo
2. Display lines in the/etc/passwd file that do not end in/bin/bash
# grep-e '/bin/bash$ '/etc/passwd
3. Display user Wang's default shell program
# grep ' ^wang '/etc/passwd | Grep-oe '/s?bin.*/.*$ '
# grep ' ^wang '/etc/passwd | Cut-d:-f7
4. Find out the two-bit or three-digit number in/etc/passwd
# Grep-eo ' [0-9]{2,3} '/etc/passwd
5. A line that displays at least one white-space character that starts with a CentOS7/etc/grub2.cfg file, followed by a non-whitespace character
# grep-e ' ^[[:space:]]+[^[:space:]]+ '/etc/grub2.cfg
6. Find the line that ends with listen followed by any number of whitespace characters in the "Netstat-tan" command result
# netstat-ant |grep-e ' listen[[:space:]]+$ '
7. Display user name and UID of all system users on CentOS7
# cat/etc/passwd|grep-e '. *:[2-9][0-9][0-9]:[0-9]+.* ' |cut-d:-f1,3
8, add user bash, Testbash, basher, SH, nologin (its shell is/sbin/nologin), find the/etc/passwd user name and shell the same name row
# cat/etc/passwd |grep-e ' ^ (. *): x:.*/\1$ ' Note the use of grep post-reference
9, take advantage of DF and grep, remove the disk partition utilization, and from large to small sort
# df |grep-e ' 1? [0-9]? [0-9]% ' |tr-s ' |sort-t '-k5-nr | Cut-d '-f5
10. Display three user root, Mage, Wang's UID and default shell
# CAT/ETC/PASSWD | Grep-e ' ^ (root|mage|wang) ' | Cut-d:-f3,7
11. Find the line at the beginning of the/etc/rc.d/init.d/functions file that has a word (including an underscore) followed by a parenthesis
# cat Functions |grep-e ' ^_*[[:alpha:]]+_*[[:alpha:]]+_*\ (' note the escape of the last parenthesis
12. Use Egrep to remove its base name in/etc/rc.d/init.d/functions
# echo "/etc/rc.d/init.d/functions" | Egrep-o ' [[: alpha:]]+$ ' note to use [[: Space:]], not [: space:], only TR uses [: space:] Similar format, because is the character ' A-Z '
# echo/etc/rc.d/init.d/functions |sed-r ' [email protected] (. */) (. +/?) [Email protected]\[email protected] ' notice if there is a difference between the characters, (. +/?) +$ Anchor Line end requires characters
13. Use Egrep to remove the directory name of the path above
# echo "/etc/rc.d/init.d/functions" | Egrep-o '. */'
14. Count the number of logins per host IP address that was logged in as root in the last command
# Last |grep-eo "([0-9]|[ 1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5]) \.) {3} ([0-9]| [1-9] [0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5]) "|sort | Uniq-c
Note that the double brackets on the previous match do not appear to be three. There are only 1. The following should also have (), grep when using the note pattern must be quoted, single quotation marks, double quotation marks can be
15. Use extended regular expressions to represent 0-9, 10-99, 100-199, 200-249, 250-255, respectively
# "([0-9]| [1-9] [0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5]) "
16. Display all IPV4 addresses in ifconfig command results
# ifconfig |grep-eo ' ([0-9]|[ 1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5]) \.) {3} ([0-9]| [1-9] [0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5]) '
17, this string: Welcome to magedu each character in Linux to go to the weight and sort, repeat the number of rows to the front
# echo "Welcome to magedu Linux" |grep-o ' | Sed '/^[[:space:]]*$/d ' |sort|uniq-c|sort-nr
Note: sed '/^$/d ' Note two slash must have, otherwise error, more insurance wording:/^[[:space:]]*$/d
18. Copy the/etc/profile to/tmp/directory and use the Find replacement command to remove the white space characters from the beginning of the/tmp/profile file
#:%s/^[[:space:]]+//
19. Copy the/etc/rc.d/init.d/functions file to the/tmp directory, and add a # number to the beginning of the line beginning with a blank character for each line of/tmp/functions with the Find replacement command
#:%s/^ \+/#&/
20, display the current time, format: 2016-06-18 10:20:30
# date "+%f%T"
21. Show the day before yesterday
# date-d '-2 day ' +%a
22. Set the current date to 2019-08-0706:05:10
# Date 080706052019.10 (month, day, year. seconds)
********************************************
File wildcard characters:
1.* match 0 or more characters
2.? Match any single character
3.[0-9] Match number range
4.[a-z] A a b b ... y y Z
5.[a-z] A b c c.. Z Z
6.[wang] matches any one of the characters in the list
7.[^wang] matches a character other than all characters in the list
Pre-defined character classes:
[[:d Igit:]]: Any number, quite with [0-9]
[[: Lower:]]: Any lowercase letter
[[: Upper:]]: Any uppercase letter
[[: Alpha:]]: Any case letter
[[: Alnum:]]: any number or letter
[[: Blank:]]: horizontal white space character
[[: Space:]]: Horizontal or vertical white space characters
********************************************
23. Display all files or directories with L, ending with a lowercase letter, and with at least one digit in the middle of the/var directory
# ls-d/var/l*[[:d igit:]]*[[:lower:]]
24. display files or directories that start with any digit in the/etc directory and end with a non-digit
# ls-d/etc/[[:d igit:]]*[^[:d igit:]]
25, display/etc/directory with a non-letter beginning, followed by a letter and any other arbitrary length of any character file or directory
# ls-d/etc/[^[:alpha:]][[:alpha:]]*
26. Display all the numbers in the/etc/directory starting with RC, followed by 0-6, other files or directories of any character
# ls-d/etc/rc[0-6]*
27. Display all files or directories ending with. D in the/etc directory
# ls-d/ETC/*.D
28. Display the files or directories with the end of. conf and beginning with m,n,r,p in the/etc directory
# ls-d/etc/[mnrp]*.conf
29. Show only hidden files and directories under/root
# ls-d/root/. [^.] *
30. Show only non-hidden directories under/etc
# ls-d/etc/*/
31, the definition of alias command baketc, every day to the/etc/directory of all files, backup to/app separate subdirectories, and require a subdirectory format of BACKUPYYYY-MM-DD, the backup process is visible
# alias baketc= ' cp-av/etc/app/backup ' date +%f '
32, create the/app/rootdir directory, and copy all the files under/root to this directory, require the retention of the original permissions
# Mkdir/app
# cp-a/root/app/rootdir
33, how to create/testdir/dir1/x,/testdir/dir1/y,/testdir/dir1/x/a,/testdir/dir1/x/b,/testdir/dir1/y/a,/testdir/dir1/y/b
# mkdir-pv/testdir/dir1/{x/,y/}{a,b}
34. How to create/testdir/dir2/x,/testdir/dir2/y,/testdir/dir2/x/a,/testdir/dir2/x/b
# mkdir-pv/testdir/dir2/{x/{a,b},y}
35, how to create/TESTDIR/DIR3,/TESTDIR/DIR4,/TESTDIR/DIR5,/TESTDIR/DIR5/DIR6,/TESTDIR/DIR5/DIR7
# mkdir-pv/testdir/dir{3,4,5/dir{6,7}}
36. Convert the contents of the/etc/issue file to uppercase and save to the/tmp/issue.out file
# tr ' A-Z ' A-Z ' </etc/issue >/tmp/issue.out
# tr ' [: Lower:] ' [: Upper:] ' </etc/issue >/tmp/issue.out
37. Convert the current system login user's information to uppercase and save to the/tmp/who.out file
# who |tr ' z-z ' A-Z ' >/tmp/who.out
38, a Linux user to the root email, request the message titled "Help", the message body is as follows:
Hello, I am Username, the system version is Here,please help me to check it, thanks!
Operating system Version Information
# mail-s ' Help ' << EOF
Hello, I am $USER,
The System version is here, please help me to check it, thanks
OS Version: ' Cat/etc/centos-release '
Eof
39, the/root/file list, displayed as a line, and the file name separated by a space
# ls/root |tr ' \ n '
40. Calculation 1+2+3+. The sum of +99+100
# echo {1..100}| Tr-s ' + ' | Bc
# seq-s "+" |BC
41. Remove the ' ^m ' character from the Windows text file
# tr-d ' \ R ' < Windows_file
# tr-d ' \15 ' < windows_file
42, processing string "Xt.,l 1 jr#! $mn 2 c*/fe 3 uz 4", keep only the numbers and spaces
# echo "Xt.,l 1 jr#" MN 2 c*/fe 3 uz 4 "| Tr-c-d ' [^0-9] '-C take reverse
43. Display the path variable in a separate row for each directory
# echo $PATH |tr ': ' \ n '
44. Replace 0-9 of the specified files into a-j
# Cat File | Tr ' 0-9 ' a-j '
45, the file/etc/centos-release each word (composed of letters) displayed in a separate line, and no blank line
# Cat/etc/centos-release | Tr ' \ n ' | Tr-d ' [:d igit:][:p unct:] ' |grep-v ' ^$ '
46, create user Gentoo, additional group is bin and root, the default shell is/BIN/CSH, the annotated message is "Gentoo distribution"
# useradd-s/bin/csh-c "Centoo distribution"-G bin,root Gentoo
47. Create the following user, group, and group memberships
Group with the name webs
User Nginx uses Webs as a subordinate group
User varnish, also using webs as a subordinate group
User MySQL, non-interactive login system, and is not a member of webs, nginx,varnish,mysql password are magedu
# Groupadd Webs
# Useradd Nginx-g Webs
# Useradd Varnish-g Webs
# useradd-r MySQL
# echo "Mage" |passwd--stdin MySQL
# echo "Mage" |passwd--stdin Varnish
# echo "Mage" |PASSWD--stdin Nginx
48. When the user Docker does not have execute permission to the/testdir directory, what does it mean that the operation cannot be done? (Only RW permissions)
# cannot switch to this directory using CD, cannot delete file under Directory, cannot display property information of file under folder
49. When the user MongoDB does not have the Read permission to the/testdir directory, what does it mean that the operation cannot be done? (Only WX permissions)
# can switch to the TestDir directory, but using LS can not see the directory of files or folders, you can delete files or folders known under the folder, but cannot use rm-f * To delete all files, you can also modify the contents of the known file
50, when the user Redis to/testdir directory without write permission, the directory of read-only files File1 can be modified and deleted? (Rx permission only)
# cannot be deleted, can delete the file and the permissions of the file is not related to the relationship, only to see if the folder has write permissions.
51, when the user Zabbix the/testdir directory has write and execute permissions, the directory of read-only files File1 can be modified and deleted?
# can modify the directory of read-only files file1, need to be forced to modify, using wq!, you can also delete file1 under the directory
52, copy the/etc/fstab file to/var/tmp, set the file owner for the Tomcat read and write permissions, the group belongs to the Apps group has read and write permissions, other people do not have permissions
# cp/etc/fstab/var/tmp
# chown Tomcat.apps/var/tmp
# chmod 660/var/tmp
53, mistakenly deleted the user git home directory, please rebuild and restore the user home directory and the corresponding permissions properties
# MKDIR-PV/HOME/GIT-M 700
# cp-a/etc/skel/. [^.] */home/git
# Chown-r Git:git/home/git
54, the new files created in/testdir/dir automatically belong to the Webs group, group apps members such as: Tomcat can have read and write access to these new files, group DBS members such as: MySQL can only have read access to new files, other users (not belonging to Webs,apps, DBS) cannot access this folder
# Groupadd Apps
# Groupadd Webs
# Groupadd DBS
# Useradd Tomcat
# useradd MySQL
# groupmems-a Tomcat-g Apps
# groupmems-a Mysql-g DBS
# chmod 770/testdir/dir
# chown Webs:webs/testdir/dir
# chmod G+s/testdir/dir
# setfacl-m G:apps:rwx/testdir/dir
# setfacl-m G:dbs:rx/testdir/dir
55. Back up ACL permissions for all files in/testdir/dir to/root/acl.txt, clear all ACL permissions in/testdir/dir, and finally restore ACL permissions
# Getfacl-r/testdir/dir >/root/acl.txt
# Setfacl-r-b/testdir/dir
# Setfacl--restore Acl.txt
56. Find the IPV4 address of this machine in Ifconfig "NIC name" command result
# ifconfig ens33 |sed-n ' 2p ' |sed-r ' s/.*inet//' |sed-r ' s/net.*//'
# ifconfig Ens33 | Sed-n ' 2p ' |sed-r ' [email protected]*inet (([0-9]{1,3}\.) {3}) ([0-9]{1,3})). *@\[email protected] ' note to enclose the entire IP as a back \1 using parentheses
57. Find out the maximum percentage value of partition space utilization
# df |grep-eo ' [[:d igit:]]{1,3}% ' |sort-nr |head-1
# df |tr-s ': ' | Sed-n ' 2, $p ' |cut-d:-f5 |sort-nr |head-1
58, identify the user UID maximum user name, UID and shell type
# cat/etc/passwd|sort-t:-k3-n-r| Head-1 |cut-d:-f1,3,7
59. Find out the permissions of/tmp and display them digitally
# 1777
60. Count the number of connections to each remote host IP currently connected to this machine, and sort from large to small
# netstat-nt |grep ' established ' |tr-s ': ' |cut-d:-f6|sort-nr |uniq-c
61. Display lines starting with size s in the/proc/meminfo file (required: use two methods)
# cat/proc/meminfo |grep-i ' ^s '
# Cat/proc/meminfo |grep ' ^[ss] '
62. Display lines in the/etc/passwd file that do not end in/bin/bash
# cat/etc/passwd |grep-v '/bin/bash$ '
63. Show user RPC default shell program
# cat/etc/passwd |grep-w ' rpc ' |sed-r ' s/.*://'
64. Find out the two-bit or three-digit number in/etc/passwd
# cat/etc/passwd |grep-eo ' [0-9]{2,3} '
65. A line that displays at least one white-space character that starts with a CentOS7/etc/grub2.cfg file, followed by a non-whitespace character
# Cat/etc/grub2.cfg | Grep-e ' ^[[:space:]]+[^[:space:]]+ '
66. Find the line that ends with listen followed by any number of whitespace characters in the "Netstat-tan" command result
# netstat-ant |grep-e ' (listen[[:space:]]*) $ '
Linux phase exercises (1)