1、列出當前系統上所有已經登錄的用戶的用戶名,注意:同一個用戶登錄多次,則只顯示一次即可。
[root@localhost ~]# who | cut -d ‘ ‘ -f1 | sort -u
root
2、取出最后登錄到當前系統的用戶的相關信息。
[root@localhost ~]# last -1 | id
uid=0(root) gid=0(root) groups=0(root) context=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023
3、取出當前系統上被用戶當作其默認shell的最多的那個shell。
[root@localhost ~]# cat /etc/passwd | cut -d ‘:’ -f7 | uniq -c |sort -n | tail -1
12 /sbin/nologin
4、將/etc/passwd中的第三個字段數值最大的后10個用戶的信息全部改為大寫后保存至/tmp/maxusers.txt文件中。
[root@localhost ~]# cat /etc/passwd | sort -n -t ‘:’ -k3 | tail -10 | tr [a-z] [A-Z] > /tmp/maxuser.txt [root@localhost ~]# cat /tmp/maxuser.txt
APACHE:X:48:48:APACHE:/USR/SHARE/HTTPD:/SBIN/NOLOGIN
SSHD:X:74:74:PRIVILEGE-SEPARATED SSH:/VAR/EMPTY/SSHD:/SBIN/NOLOGIN
DBUS:X:81:81:SYSTEM MESSAGE BUS:/:/SBIN/NOLOGIN
POSTFIX:X:89:89::/VAR/SPOOL/POSTFIX:/SBIN/NOLOGIN
NOBODY:X:99:99:NOBODY:/:/SBIN/NOLOGIN
SYSTEMD-NETWORK:X:192:192:SYSTEMD NETWORK MANAGEMENT:/:/SBIN/NOLOGIN
POLKITD:X:999:997:USER FOR POLKITD:/:/SBIN/NOLOGIN
USER3:X:1000:1000::/HOME/USER3:/BIN/BASH
MAGEIA:X:1100:1100::/HOME/LINUX:/BIN/BASH
SLACKWARE:X:2002:2016::/HOME/SLACKWARE:/BIN/TCSH
5、取出當前主機的IP地址,提示:對ifconfig命令的結果進行切分。
[root@localhost ~]# ifconfig ens32 | grep netmask
inet 10.62.121.203 netmask 255.255.255.0 broadcast 10.62.121.255
6、列出/etc目錄下所有以.conf結尾的文件的文件名,并將其名字轉換為大寫后保存至/tmp/etc.conf文件中。
[root@localhost ~]# ls /etc | egrep ‘.conf$’ | tr [a-z] [A-Z] > /tmp/etc.conf
[root@localhost ~]# cat /tmp/etc.conf
ASOUND.CONF DRACUT.CONF E2FSCK.CONF FUSE.CONF GEOIP.CONF HOST.CONF KDUMP.CONF KRB5.CONF LD.SO.CONF LIBAUDIT.CONF LIBUSER.CONF LOCALE.CONF LOGROTATE.CONF MAN_DB.CONF MKE2FS.CONF NSSWITCH.CONF PEAR.CONF RESOLV.CONF RSYSLOG.CONF SESTATUS.CONF SUDO.CONF SUDO-LDAP.CONF SYSCTL.CONF VCONSOLE.CONF YUM.CONF
7、顯示/var目錄下一級子目錄或文件的總個數。
[root@localhost ~]# ll /var | wc -l
23
8、取出/etc/group文件中第三個字段數值最小的10個組的名字。
[root@localhost ~]# cat /etc/group | sort -n -t ‘:’ -k3 | head -10 | cut -d ‘:’ -f1
root
bin
daemon
sys
adm
tty
disk
lp
mem
kmem
9、將/etc/fstab和/etc/issue文件的內容合并為同一個內容后保存至/tmp/etc.test文件中。 [root@localhost ~]# cat /etc/{fstab,issue} > /tmp/etc.test
[root@localhost ~]# cat /tmp/etc.test
#
# /etc/fstab
# Created by anaconda on Wed Jun 20 19:23:36 2018
#
# 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 0
UUID=59cf1232-fa3f-478c-8f86-887f7d7e25a4 /boot xfs defaults 0 0
/dev/mapper/centos-home /home xfs defaults 0 0
/dev/mapper/centos-swap swap swap defaults 0 0
\S
Kernel \r on an \m
10、請總結描述用戶和組管理類命令的使用方法并完成以下練習:
(1)、創建組distro,其GID為2016;
groupadd -g 2016 distro
(2)、創建用戶mandriva, 其ID號為1005;基本組為distro;
useradd -u 1005 -g distro mandriva
(3)、創建用戶mageia,其ID號為1100,家目錄為/home/linux;
useradd -u 1100 -d /home/linux mageia
(4)、給用戶mageia添加密碼,密碼為mageedu;
[root@localhost ~]# echo “magedu” | passwd –stdin mageia
Changing password for user mageia. passwd: all authentication tokens updated successfully.
(5)、刪除mandriva,但保留其家目錄;
userdel mandriva
(6)、創建用戶slackware,其ID號為2002,基本組為distro,附加組peguin;
useradd -u 2002 -g distro -G peguin slackware
(7)、修改slackware的默認shell為/bin/tcsh;
[root@localhost ~]# usermod -s /bin/tcsh slackware
[root@localhost ~]# grep slackware /etc/passwd slackware:x:2002:2016::/home/slackware:/bin/tcsh
(8)、為用戶slackware新增附加組admins;
[root@localhost ~]# groupadd admins
[root@localhost ~]# usermod -G admins -a slackware
[root@localhost ~]# id slackware
uid=2002(slackware) gid=2016(distro) groups=2016(distro),2017(peguin),2018(admins
本文來自投稿,不代表Linux運維部落立場,如若轉載,請注明出處:http://www.www58058.com/102439