Linux lookup filtering and some examples of user and group management commands _linux

Source: Internet
Author: User
Tags echo command stdin

1. List the username of all logged-in users on the current system, and note that the same user logs on more than once, only one display at a time.

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

2. Lists information about the last user who logged on to the current system.

~]# last | head -1

3. List the most common shell that the user is currently on the system as the default shell.

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

4. Change all the information in the third field in the/etc/passwd to the top 10 users and save 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 address of the current host, hint: ifconfig The result of the command.

~]#ifconfig | grep '[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}'

6. List all the file names in the/etc directory that end with. conf, and convert their 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. Displays the total number of subdirectories or files at the next level in the/var directory.

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

8. Remove the name of the 10 group with the lowest numerical value in the third field in the/etc/group file.

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

9. The contents of the/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

10. Summarize the methods used to describe user and group management commands and complete the following exercises:

(1) Create group distro with a GID of 2016

~]# groupadd distro -g 2016

(2) Create user Mandriva, whose ID number is 1005; basic group is distro;

~]# useradd mandriva -u 1005 -g distro

(3) Create user Mageia, its ID number is 1100, home directory is/home/linux;

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

(4) Add the password to the user Mageia, the secret is mageedu;

~]# echo "mageeu" | passwd –stdin mageia

(5) Delete Mandriva, but keep its home directory;

~]# userdel mandriva

(6) Create user Slackware, its ID number is 2002, Basic Group is distro, additional group Peguin;

~]# useradd slackware -u 2002 -g distro -G peguin

(7) Modify the default shell of Slackware to/BIN/TCSH;

~]# usermod -s /bin/tcsh slackware

(8) Adding additional Group admins for user Slackware;

~]# usermod -a -G admins slackware

(9) Add a password for the Slackware, and require a minimum password of 3 days, up to 180 days, warning for 3 days;

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

(10) Add the user OpenStack, its ID number is 3003, the basic group is clouds, the additional group is Peguin and Nova;

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

(11) Add the system user MySQL, request its shell for/sbin/nologin;

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

(12) Use the Echo command to add a password for OpenStack;

~]# echo openstack | passwd –stdin openstack

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: info-contact@alibabacloud.com 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.