Linux search and filtering and user and group management command usage

Source: Internet
Author: User
Tags echo command stdin

1. List the usernames of all logged-on users on the current system. Note: Only one user can be logged on multiple times.

~] # Who | cut-d ''-f1 | sort | uniq

2. List the information about the users logging on to the current system.

~] # Last | head-1

3. List the shell on the current system that is most used as the default shell.

~] # Cut-d:-f7/etc/passwd | uniq-c | sort-n | tail-1

4. Change the information of the last 10 users with the maximum value of the Third Field in/etc/passwd to uppercase and save the information to the/tmp/maxuser.txt file.

~] # Sort-t:-k3-n/etc/passwd | tail | tr 'A-z'' a-Z'>/tmp/maxuser.txt

5. List the IP addresses of the current host. The prompt is: split the result 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 with. conf in the/etc directory, convert the names to uppercase, and save them to the/tmp/etc. conf file.

~] # Find/etc/-name "*. conf" | tr 'A-z'' a-Z'>/tmp/etc. conf

7. Display the total number of subdirectories or files under the/var directory.

~] # Ls-d/var/* | wc-l

8. Retrieve the names of the 10 groups with the minimum value of the third field in the/etc/group file.

~] # Sort-t:-k3-n/etc/group | cut-d:-f1 | head

9. Merge the/etc/fstab and/etc/issue files into the same content and save it to the/tmp/etc. test file.

~] # Cat/etc/fstab/etc/issue>/tmp/etc. test

10. Summarize the usage of user and group management commands and complete the following exercises:

(1) create a distro group whose GID is 2016

~] # Groupadd distro-g 2016

(2) create a user named "mandriva", whose ID number is 1005, and the BASIC group is "distro;

~] # Useradd mandriva-u 1005-g distro

(3) Create a mageia user. The ID number is 1100, and the home directory is/home/linux;

~] # Useradd mageia-u 1100-s/home/linux

(4) add a password for mageia to the user. The password is mageedu;

~] # Echo "mageeu" | passwd-stdin mageia

(5) delete mandriva, but keep its home directory;

~] # Userdel mandriva

(6) create the slackware user. The 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 slackware's default shell to/bin/tcsh;

~] # Usermod-s/bin/tcsh slackware

(8) add an additional group admins for slackware;

~] # Usermod-a-G admins slackware

(9) add a password for slackware. The minimum password validity period is 3 days, the maximum password is 180 days, and the warning is 3 days;

~] # Passwd slackware-n 3-x 180-w 3

(10) add an openstack user. The ID number is 3003, the BASIC group is clouds, and the additional groups are peguin and nova;

~] # Useradd openstack-u 3003-g clouds-G penguin, nova

(11) add the system user mysql and require the shell to be/sbin/nologin;

~] # Useradd-r mysql-s/sbin/nologin

(12) use the echo command to add a password for openstack in non-interactive mode;

~] # Echo openstack | passwd-stdin openstack

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.