linux looks for instances of filtering and user and group management commands
- 2020-05-10 23:21:19
- OfStack
1. List the user names of all users who have logged in on the current system. Note: if the same user logs in multiple times, it will only be displayed once.
~]# who | cut -d' ' -f1 | sort | uniq
2. List information about the last user who logged into the current system.
~]# last | head -1
3. List the most common shell on the current system that users use as their default shell.
~]# cut -d: -f7 /etc/passwd | uniq -c | sort -n | tail -1
4. Change all the information of the last 10 users with the largest value in the third field /etc/passwd to uppercase and save it to the file /tmp/ maxuser.txt.
~]# sort -t: -k3 -n /etc/passwd | tail | tr 'a-z' 'A-Z' > /tmp/maxuser.txt
5. List the IP address of the current host. Prompt: shard the results of the ifconfig command.
~]#ifconfig | grep '[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}'
6. List all file names ending in.conf in the /etc directory and save them to /tmp/ etc.conf file after converting their names to uppercase.
~]# find /etc/ -name "*.conf" | tr 'a-z' 'A-Z' > /tmp/etc.conf
7. Display the total number of level 1 subdirectories or files in the /var directory.
~]# ls -d /var/* | wc -l
8. Fetch the names of the 10 groups with the smallest value in the third field in the /etc/group file.
~]# sort -t: -k3 -n /etc/group | cut -d: -f1 | head
9. Merge the contents of /etc/fstab and /etc/issue files into the same content and save them to /tmp/ etc.test files.
~]# cat /etc/fstab /etc/issue > /tmp/etc.test
10. Summarize and describe the use of user and group management commands and complete the following exercises:
(1) create group distro, whose GID is 2016
~]# groupadd distro -g 2016
(2) create user mandriva, whose ID number is 1005; The base group is distro;
~]# last | head -1
0
(3) create user mageia, whose ID number is 1100 and whose home directory is /home/linux;
~]# useradd mageia -u 1100 -s /home/linux
(4) add password to user mageia, which is mageedu;
~]# echo "mageeu" | passwd �stdin mageia
(5) delete mandriva, but keep its home directory;
~]# userdel mandriva
(6) create user slackware, whose ID number is 2002, the basic group is distro, and the additional group is peguin;
~]# useradd slackware -u 2002 -g distro -G peguin
(7) modify the default shell of slackware to be /bin/tcsh;
~]# usermod -s /bin/tcsh slackware
(8) add additional group admins for user slackware;
~]# usermod -a -G admins slackware
(9) add a password for slackware, and require the password to be used for a minimum of 3 days, a maximum of 180 days, and a warning for 3 days;
~]# passwd slackware -n 3 -x 180 -w 3
(10) add user openstack, whose ID number is 3003, the base group is clouds, and the additional groups are peguin and nova;
~]# useradd openstack -u 3003 -g clouds -G penguin,nova
(11) add system user mysql, requiring its shell to be /sbin/nologin;
~]# useradd -r mysql -s /sbin/nologin
(12) use the echo command to add password for openstack non-interactively;
~]# cut -d: -f7 /etc/passwd | uniq -c | sort -n | tail -1
0