Megeedu Linux+python Advanced Operations 3 period three weeks

Source: Internet
Author: User
Tags echo command gopher


1. List the user name of all logged-in users on the current system, note: The same user logged in multiple times, only once.

[Email protected] ~]# whoroot pts/0 2016-08-19 17:46 (172.16.168.16) root pts/1 2016-08-19 17:46 (17 2.16.168.16) [[email protected] ~]# who | Cut-d '-f1 | Uniq Root[[email protected] ~]#

2. Remove the information about the user who last logged in to the current system.

[[email protected] ~]# whoroot      pts/0        2016-08-19 17:46  (172.16.168.16) root      pts/1        2016-08-19 17:46  (172.16.168.16) root     pts/2         2016-08-19 17:53  (172.16.168.16) [[Email protected] ~]# who | tail -n  1root     pts/2        2016-08-19  17:53  (172.16.168.16) [[email protected] ~]# who | tail -n 1 |  cut -d  '    -f1 | iduid=0 (root)  gid=0   group =0 (root)   environment = unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023[[email protected] ~]# 

3. Remove the shell that is the user's default shell on the current system.

[Email protected] ~]# CAT/ETC/PASSWD | Cut-d ': '-f7 | uniq-c | Sort-n | Tail-n 1 11/sbin/nologin[[email protected] ~]#

4, the information of the third field in/ETC/PASSW D with the largest number of the first 10 users is changed to uppercase and then saved to the/tmp/maxusers.txt file.

[[Email protected] ~]# cat /etc/passwd | sort -n -k 3 -t   ': '  | tr  ' A-Z '   ' A-Z '  >> /tmp/maxusers.txt      [[email protected] ~]# cat /tmp/maxusers.txt root:x:0:0:root:/root:/bin/bashbin : x:1:1:bin:/bin:/sbin/nologindaemon:x:2:2:daemon:/sbin:/sbin/nologinadm:x:3:4:adm:/var/adm:/sbin/nologinlp:x : 4:7:lp:/var/spool/lpd:/sbin/nologinsync:x:5:0:sync:/sbin:/bin/syncshutdown:x:6:0:shutdown:/sbin:/sbin/ shutdownhalt:x:7:0:halt:/sbin:/sbin/haltmail:x:8:12:mail:/var/spool/mail:/sbin/nologinuucp:x:10:14:uucp:/var/ spool/uucp:/sbin/nologinoperator:x:11:0:operator:/root:/sbin/nologingames:x:12:100:games:/usr/games:/sbin/ Nologingopher:x:13:30:gopher:/var/gopher:/sbin/nologinftp:x:14:50:ftp user:/var/ftp:/sbin/nologinvcsa:x : 69:69:virtual console memory owner:/dev:/sbin/nologinsshd:x:74:74:privilege-separated ssh :/var/empty/sshd:/sbin/nologinposTfix:x:89:89::/var/spool/postfix:/sbin/nologinnobody:x:99:99:nobody:/:/sbin/nologinsaslauth:x:499:76:saslauthd  user:/var/empty/saslauth:/sbin/nologin[[email protected] ~]#

5, take out the IP address of the current host, hint: The result of ifconfig command is sliced.

[Email protected] ~]# ifconfig eth0 | grep ' inet addr ' | Cut-d ': '-f2 | Cut-d '-f1172.16.168.9[[email protected] ~]#

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.

[Email protected] ~]# ls/etc/*.conf | Cut-d '/'-f3 | Tr ' A-Z ' A-Z ' >/tmp/etc.conf [[email protected] ~]# cat/tmp/etc.conf dracut. Confgai. Confgrub. Confhost. Confinit. Confkdump. CONFKRB5. Confld. So. Conflibaudit. Conflibuser. Conflogrotate. Confmke2fs. Confnsswitch. Confresolv. Confrsyslog. Confsestatus. Confsudo. Confsudo-ldap. Confsysctl. Confyum. Conf[[email protected] ~]#

7. Displays the total number of sub-directories or files in the/var directory.

[[email protected] ~]# Ls/var/cache db Games l2e3d l3ed Lib lock mail opt run Tmpcrash empty l22d l333d Le3d local log NIS preserve spool yp[[email protected] ~]# ls/var/| Wc-l22[[email protected] ~]#

8. Remove the names of the 10 groups with the smallest number of the third field in the/etc/group file.

[Email protected] ~]# Cat/etc/group | Sort-n-K 3-t ': ' | Head-n 10 | Cut-d ': '-f1rootbindaemonsysadmttydisklpmemkmem[[email protected] ~]#

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.

[[email protected] ~]# cat /etc/fstab ## /etc/fstab# created by  Anaconda on fri jul 29 07:03:27 2016## accessible filesystems, by  reference, are maintained under  '/dev/disk ' # see man pages fstab (5),  findfs (8),  mount (8)  and/or blkid (8)  for more info#/dev/mapper/ volgroup-lv_root /                        ext4    defaults         1 1UUID=5d921146-c901-4504-8266-21e100ccb7a3 /boot                    ext4     defaults        1 2/dev/mapper/volgroup-lv_home  /home                   ext4     defaults        1 2/dev/mapper/volgroup-lv_swap  swap                     swap    defaults        0  0tmpfs                    /dev/shm                 tmpfs   defaults        0 0devpts                   / Dev/pts                devpts   gid=5,mode=620  0 0sysfs                    /sys                     sysfs   defaults         0 0proc                     /proc                    proc    defaults         0 0[[email protected] ~]# cat /etc/issueCentOS  release 6.8  (Final) kernel \r on an \m[[email protected] ~]# cat  /etc/fstab /etc/issue >> /tmp/etc.test[[email protected] ~]# cat  /tmp/etc.test ## /etc/fstab# created by anaconda on fri jul 29 07:03:27 2016##  accessible filesystems, by reference, are maintained under  '/dev/disk ' #  see man pages fstab (5),  findfs (8),  mount (8)  and/or blkid (8)  for  more info#/dev/mapper/VolGroup-lv_root /                        ext4     defaults        1 1uuid= 5d921146-c901-4504-8266-21e100ccb7a3 /boot                    ext4    defaults         1 2/dev/mapper/VolGroup-lv_home /home                &nBsp;   ext4    defaults        1  2/dev/mapper/VolGroup-lv_swap swap                     swap    defaults         0 0tmpfs                    /dev/shm                 tmpfs   defaults         0 0devpts                   /dev/pts                 devpts  gid=5,mode=620  0 0sysfs                    /sys                     sysfs   defaults         0 0proc                     /proc                    proc     defaults        0 0CentOS release 6.8  (Final ) kernel \r on an \m[[email protected] ~]#

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

(1), create group distro, its GID is 2016;

[Email protected] ~]# groupadd-g distro

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

[Email protected] ~]# useradd-u 1005-g distro Mandriva

(3), create user Mageia, whose ID number is 1100, home directory is/home/linux;

[Email protected] ~]# useradd-u 1100-d/home/linux Mageia

(4), to the user mageia add password, password for mageedu;

[Email protected] ~]# echo "mageedu" |passwd--stdin Mageia

(5), delete Mandriva, but retain their home directory;

[Email protected] ~]# Userdel Mandriva

(6), create user Slackware, its ID number is 2002, the basic group is distro, additional group Peguin;

[Email protected] ~]# groupadd peguin[[email protected] ~]# useradd-u 2002-g distro-g Peguin Slackware

(7), modify the Slackware default shell for/BIN/TCSH;

[Email protected] ~]# usermod-s/bin/tcsh Slackware

(8), add additional Group admins for user Slackware;

[Email protected] ~]# groupadd Admins && usermod-g Admins slackware-a

(9), add password for Slackware, and require the minimum password age of 3 days, the maximum is 180 days, warning for 3 days;

[Email protected] ~]# passwd slackware-n 3-x 180-w 3

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

[[email protected] ~]# groupadd clouds[[email protected] ~]# groupadd nova[[email protected] ~]# useradd-u 3003-g clouds -G Peguin,nova openstack[[email protected] ~]#

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

[Email protected] ~]# useradd-r mysql-s/sbin/nologin

(12), use the echo command, non-interactive add a password for OpenStack.

[Email protected] ~]# echo "123456" |passwd--stdin OpenStack


This article from "blog" blog, declined reprint!

Megeedu Linux+python Advanced Operations 3 period three weeks

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: 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.