1. List the user name of all logged-in users on the current system, note: The same user login multiple times, only one time can be displayed
~]# who | Sort-u
- Who: View details of all users who are currently logged in
- Sort-u: Removing duplicate rows in the output line
2. Remove information about the user who last logged in to the current system
~]# who | Tail-1
3. Remove the shell that is the user's default shell on the current system.
~]# CAT/ETC/PASSWD | Cut-d:-f7 | uniq-c | Sort-n | Tail-1
- Cut-d:-f7: Specifies the delimiter to take the shell field value
- UNIQ-C: Show Repeat Count
- Sort-n: Sort by numeric size
- TAIL-1: Get last line
4, the third field in the/etc/passwd value of the largest 10 users of the information is changed to uppercase and saved to the/tmp/maxusers.txt file
~]# cat/etc/passwd |sort-t:-K 3-n/etc/passwd |tail-n 10 | tr [A-z] [a-z] >>/tmp/maxusers.txt
- SORT-T: Field delimiter
- Sort-k 3: Take the third field as a standard sort
- tr [A-z] [a-z]: Convert lowercase in a file to size
- ">>": Append redirect, new content appended to end of target file
5, take out the IP address of the current host, hint: The result of the ifconfig command is sliced ~]# ifconfig |grep-a 3 "^e[tn]" |grep-o-i "inet. $ "| grep-o" [0-9]. $"| Cut-d '-f1
- Grep-a 3 "^e[tn]": matches to the following 3 lines, displaying information with T and n letters beginning with E
- Grep-o: Show only the matching string
- Grep-i: Ignoring character casing
- "Inet. $ ":. Match any character after inet $: end of line anchoring
- Cut-d '-f1: Intercept separator character first column
6. List the file names of all files ending with. conf in/etc directory and convert their names to uppercase and save them to the/tmp/etc.conf file
~]# ls-a/etc/*.conf | Tr ' A-Z ' A-Z ' >>/tmp/etc.conf
7. Display the total number of sub-directories or files in the/var directory
~]# Ls-a/var | Wc-l
8. Remove the name of the 10 group with the lowest value in the third field in the/etc/group file
~]# sort-t:-k3-n/etc/group | Head-n 10
- Head-n 10: Display the first 10 rows of data in a file
9, the contents of/etc/fstab and/etc/issue files are merged into the same content and saved to the/tmp/etc.test file
~]# cat/etc/fstab/etc/issue &>/tmp/etc.test
- &>: Overwrite redirect
10. Summarize the methods used to describe the user and group management commands and complete the following exercises
- (1) Create a group distro with a GID number of 2016
- (2) Create user Andriva, whose ID number is 1005; Basic Group is distro
- ~]# useradd-u 1005-g distro Andriva
- (3) Create user Mageia, whose ID number is 1100, home directory is/home/linux
- ~]# useradd-u 1100-d/home/linux Mageia
- (4) Add password to user Mageia, password is mageedu
- ~]# echo ' mageedu ' | passwd--studin Mageia
- (5) Delete Andriva, but keep its home directory
- (6) Create user Slackte, whose ID number is 2002, Basic Group is distro, additional group Peguin
- ~]# useradd-u 2002-g distro-g Peguin Slackte
- USERADD-G: Specifies the base group ID, and the group must exist beforehand, or it will error
- Useradd-g: Indicates the additional group to which the user belongs
- (7) Modify the default shell of Slackte to/BIN/TCSH
- ~]# chmod-s/bin/tcsh Slackware
*useradd-s: Indicates the user's default shell, and all available shells are stored in the/etc/shells file
- (8) Add additional groups for user Slackte Admins
- ~]# usermod-g Admins Slackware
N33-week 3-Sunflower