字符切割和用戶管理

1、列出當前系統上所有已經登錄的用戶的用戶名,同一個用戶登錄多次,則只顯示一次

who |cut -d’ ‘ -f1 |sort -u
2、取出最后登錄到當前系統的用戶的相關信息。

last |head -1|cut -d’ ‘ -f1

3、取出當前系統上被用戶當作其默認shell的最多的那個shell。

cut -d: -f7 /etc/passwd|uniq -c|sort -n|tail -1
4、將/etc/passwd中的第三個字段數值最大的后10個用戶的信息全部改為大寫后保存至/tmp/maxusers.txt文件中。

sort -t: -k3 -n /etc/passwd | tail -10 | tr ‘a-z’ ‘A-Z’ > /tmp/maxusers.txt
5、取出當前主機的IP地址。

ifconfig ens33|grep netmask|cut -d’ ‘ -f10
6、列出/etc目錄下所有以.conf結尾的文件的文件名,并將其名字轉換為大寫后保存至/tmp/etc.conf文件中。

ls –d /etc/*.conf | tr ‘a-z’ ‘A-Z’ >/tmp/etc.conf
7、顯示/var目錄下一級子目錄或文件的總個數。

ls /var |wc -l
8、取出/etc/group文件中第三個字段數值最小的10個組的名字。

sort -t: -k3 -n /etc/group |head -10|cut –d: -f1
9、將/etc/fstab和/etc/issue文件的內容合并為同一個內容后保存至/tmp/etc.test文件中。

cat /etc/fstab >> /etc/issue
10、請總結描述用戶和組管理類命令的使用方法并完成以下練習:
(1)、創建組distro,其GID為2016;

groupadd ?distro ?–g2016
(2)、創建用戶mandriva, 其ID號為1005;基本組為distro;

useradd mandriva –u1005 –g2016
(3)、創建用戶mageia,其ID號為1100,家目錄為/home/linux;

useradd mageia –u1100 –d /home/linux
(4)、給用戶mageia添加密碼,密碼為mageedu;

echo “mageedu” |passwd –stdin mageia
(5)、刪除mandriva,但保留其家目錄;

userdel mandriva
(6)、創建用戶slackware,其ID號為2002,基本組為distro,附加組peguin;

useradd slackware –u2002 –g2016 –Gpeguin
(7)、修改slackware的默認shell為/bin/tcsh;

usermod slackware? -s/bin/tcsh
(8)、為用戶slackware新增附加組admins;

usermod –G admins slackware

本文來自投稿,不代表Linux運維部落立場,如若轉載,請注明出處:http://www.www58058.com/90311

(0)
N28--李冬N28--李冬
上一篇 2017-12-17
下一篇 2017-12-17

相關推薦

  • 接51CTO:13 用戶組和權限管理3

    用戶組和權限管理3 一、雜項知識整理 1、硬鏈接:寫源文件可以是相對地址,相對于鏈接文件。例如 [root@localhost testdir]# ln ../etc/fstab aaa ln: 無法創建硬鏈接"aaa" => "../etc/fstab…

    Linux干貨 2016-08-04
  • N26-第五周博客作業

    一、顯示當前系統上root、fedora或user1用戶的默認shell; [root@promote home]# grep -E ‘^(root|fedora|user1)’ /etc/passwd |cut -d : -f7 /bin/bash /bin/bash /bin/bash [root@promote home]# 注…

    Linux干貨 2017-05-15
  • TIME_WAIT引起Cannot assign requested address報錯

    1.  問題描述      有時候用redis客戶端(php或者java客戶端)連接Redis服務器,報錯:“Cannot assign requested address?!?     原因是客戶端頻繁的連接服務器,由于每次連接都在很短時間內結束,導致很多的TIME_WAIT。所以新的連…

    Linux干貨 2016-03-09
  • 第八周作業

    第八周作業 1、寫一個腳本,使用ping命令推測172.16.250.1-172.16.250.254之間的所有主機的在線狀態; 在線的主機使用綠色顯示; 不在線的主機使用紅色顯示;   #!/bin/bash for i in {1..254};do if ping -c 1 -w 1 192.168.1.$i &> /dev/nu…

    Linux干貨 2017-11-13
  • 0803作業

    課上練習 1.當用戶xiaoming 對/testdir  目錄無執行權限時,意味著無法做哪些操作?  drwxr-xr–. 14 root root 4096 Aug  3 13:35 /testdir [xiaoming@localhost ~]$ touch /testdir/f1…

    Linux干貨 2016-08-04
  • NFS實現共享wordpress

    實驗環境 192.168.68.134 wordpress站點 nfs-server 192.168.68.144 nfs-client   實驗要求 nfs server共享/var/www/html目錄 nfs clinet掛載nfs-server共享的目錄,部署wordpress   nfs server端 先部署wordpress…

    Linux干貨 2017-10-21

評論列表(1條)

  • 馬哥教育
    馬哥教育 2018-01-07 16:21

    內容基本上基本沒什么問題,如果能給出操作之后的結果,會更好。繼續加油~

欧美性久久久久