Linux third time job

Source: Internet
Author: User
Tags echo command

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] ~]# who | Cut-d '-F 1//Cut string,-D indicates the character is a space,-F, 1th column Jun_shaojun_shaojun_shaojun_shaorootroot[[email protected] ~]# who | Cut-d '-F 1 | Sort-u Jun_shaoroot

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

[[EMAIL PROTECTED] ~]$ WHO | SORT  -R -K 3JUN_SHAO PTS/5         2016-08-20 01:09  (192.168.0.100) root      pts/4        2016-08-20 00:34  ( 192.168.0.100) root     pts/3         2016-08-20 00:34  (192.168.0.100) jun_shao pts/2         2016-08-20 00:33  (192.168.0.100) jun_shao pts/1         2016-08-20 00:33  (192.168.0.100) jun_shao pts/0         2016-08-20 00:32  (: 0) jun_shao :0            2016-08-20 00:31  (: 0) [[email protected] ~]$ who | sort  -r  -k 3 | head -n 1 jun_shao pts/5        2016-08-20 01:09  ( 192.168.0.100) [[email protected] ~]$ who | sort  -r -k 3 |  head -n 1 > /tmp/last.txt[[email protected] ~]$ cat /tmp/ last.txt jun_shao pts/5        2016-08-20 01:09  ( 192.168.0.100)


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

[Email protected] ~]$ cut-d:-F 7/etc/passwd | Sort | uniq-c | Sort-f | Tail-n 1 >/tmp/shell.txt[[email protected] ~]$ cat/tmp/shell.txt 39/sbin/nologin


4, the third field in the/etc/passwd the value of the largest 10 users of the information is changed to uppercase and saved to the/tmp/maxusers.txt file.

[[email protected] ~]$ sort -t : -k 3 -n /etc/passwd |  tail -n 10 | tr [a-z] [a-z] > /tmp/maxusers.txt[[email  Protected] ~]$ cat /tmp/maxusers.txt geoclue:x:992:989:user for geoclue:/var/lib /geoclue:/sbin/nologinlibstoragemgmt:x:993:990:daemon account for libstoragemgmt:/var/run/lsm:/ Sbin/nologinsaslauth:x:994:76:saslauthd user:/run/saslauthd:/sbin/nologincolord:x:995:992:user for  colord:/var/lib/colord:/sbin/nologinunbound:x:996:993:unbound dns resolver:/etc/unbound:/sbin/ nologinpolkitd:x:997:995:user for polkitd:/:/sbin/nologinsystemd-network:x:998:996:systemd  network management:/:/sbin/nologinsystemd-bus-proxy:x:999:997:systemd bus proxy:/:/sbin/ nologinjun_shao:x:1000:1000:jun_shao:/home/jun_shao:/bin/bashnfsnobody:x:65534:65534:anonymous nfs  User:/var/lib/nfs:/sbin/nologin 


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

[Email protected] ~]$ Ifconfig eno16777736 | Grep-w "inet" | Cut-d '-F 10192.168.0.101

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] jun_shao]# ls/etc/|grep ' \.conf$ ' >/tmp/etc.conf[[email protected] jun_shao]# cat/tmp/etc.conf Asound.confautofs.confautofs_ldap_auth.confbrltty.confcgconfig.confcgrules.confcgsnapshot_ Blacklist.confchrony.confdleyna-server-service.confdnsmasq.confdracut.confe2fsck.conffprintd.conffuse.confhba.confhost.co Nfidmapd.confipsec.confkdump.confkrb5.confksmtuned.confld.so.conflibaudit.conflibuser.conflocale.conflogrotate.confman _db.confmke2fs.confmtools.confnfsmount.confnsswitch.confntp.confnumad.confoddjobd.confpbm2ppa.confpnm2ppa.confradvd.confr Equest-key.confresolv.confrsyncd.confrsyslog.confsestatus.confsos.confsudo.confsudo-ldap.confsysctl.conftcsd.confupdatedb . confusb_modeswitch.confvconsole.confwvdial.conf

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

[Email protected] ~]$ Ll-a/var/| Wc-l26


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-t:-K 3-n-r | Tail-n 10kmem:x:9:mem:x:8:lp:x:7:disk:x:6:tty:x:5:adm:x:4:sys:x:3:daemon:x:2:bin:x:1:root:x:0:


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/issue > /tmp/etc.test [[ email protected] ~]$ cat /tmp/etc.test ## /etc/fstab# created by  Anaconda on wed aug 17 16:50:22 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/ centos-root /                        xfs     defaults         0 0UUID=be50a901-277e-4252-b8be-717299df19f5 /boot                    xfs      defaults        0 0/dev/mapper/centos-swap swap                     swap     defaults        0 0\SKernel \r  On an \m


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] jun_shao]# groupadd-g distro


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

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


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

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

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

[Email protected] jun_shao]# passwd mageia changing password for user Mageia. New Password:bad password:the password is shorter than 8 characters retype new Password:passwd:all authe Ntication Tokens updated successfully.

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

[Email protected] home]# Userdel Mandriva [[email protected] home]# ls Jun_shao linux m Andriva

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

[Email protected] home]# groupadd Peguin [[email protected] home]# useradd-u 2002-g distro-g Pegui n Slackware [[email protected] home]# ID slackware uid=2002 (slackware) gid=2016 (distro) groups=2016 (distro) (p Eguin)


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

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

[Email protected] home]# tail-n 1/etc/passwd slackware:x:2002:2016::/home/slackware:/bin/tcsh


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

[Email protected] jun_shao]# usermod-a-G admins slackware [[email protected] jun_shao]# ID slackware uid=2002 ( Slackware) gid=2016 (distro) groups=2016 (distro), Peguin (2018)

(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] jun_shao]# passwd Slackware |     passwd slackware-n 3-x 180-w 3 Adjusting aging data for user Slackware.      passwd:success new Password:bad password:the password is shorter than 7 characters retype New password: [Email protected] jun_shao]# tail-n 1/etc/shadow Slackware:$6$6sp2wfd/$9oyf6m0wbsnb/qvmekcy/qaa494ctedvdwx2jktap Of.. 6ud.ycenkpe3byuwfr20wy6dwdiu6x1fioum6kd20:17033:3:180:3:::



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

[Email protected] jun_shao]# useradd-u 3003-g clouds-g Peguin,nova openstack [[email protected] Ju n_shao]# ID OpenStack uid=3003 (openstack) gid=2019 (Clouds) groups=2019 (Clouds), Peguin (Nova)


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

[Email protected] jun_shao]# useradd-r-s/sbin/nologin MySQL [[email protected] jun_shao]# tail-n 1/ETC/PASSWD Mysql:x:987:982::/home/mysql:/sbin/nologin


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

[[email protected] jun_shao]# echo "admin" | passwd--stdin OpenStack


This article is from "June's personal blog" blog, please be sure to keep this source http://june1015.blog.51cto.com/4804270/1840705

Linux third time job

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.