Linux Experiment 3 Find related

1. Display the usernames and UIDs of all system users.

cut -d: -f1,3 /etc/passwd |grep "\<[[:digit:]]\{1,3\}\>"

Insert image description here

2. Display the users whose default shell is sbin/nologio in the etc/passwd file.

cat /etc/passwd |grep "sbin/nologin"

Insert image description here

3. Display the users whose default shell is bin/bash in the etc/passwd file.

cat /etc/passwd |grep "bin/bash"

Insert image description here

4. Find the one-digit or two-digit number in the /etc/passwd file.

cat /etc/passwd|grep -o "\<[0-9]\{1,2\}\>"

Insert image description here

5. Display lines starting with at least one blank character in /boot/grub/grub.conf.

cat /etc/grub2.cfg |grep "^ "

Insert image description here

6. Display the lines in the /etc/rc.d/rc.sysinit file that begin with #, followed by at least one blank character, and then at least one non-blank character.

cat /etc/rc.d/rc.local | grep "^#\s.\+\S"    #小写s是空白字符、大写S是非空白字符

Insert image description here
The second method

cat etc/rc.d/rc.local |grep "^[#]\+[[:space:]].\+[^[:space:]]"

Insert image description here

7. Add users bash, testbash, basher.nologin (this user’s shell is /sbin/nologin). Then find out the information of other users on the current system whose username is the same as the default shell.

cat /etc/passwd|grep "\(^.*\)\>.*/\1$"

Insert image description here

Guess you like

Origin blog.csdn.net/qq_45477065/article/details/124358455