作業練習:3

來源:互聯網
上載者:User

標籤:作業練習:3

1、列出當前系統上的所有已經登入的使用者的使用者名稱,注意:同一個使用者登入多次,則只顯示一次即可

who | cut -d ‘ ‘  -f1 | sort -u


2、取出最後登入到當前系統的使用者的相關資訊

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


3、取出當前系統上被使用者當作其預設shell的最多的那個shell

cat /etc/passwd | cut -d: -f7 | uniq -c | sort -n  | tail -n 1


4、將/etc/passwd中的第三個欄位數值最大的後10個使用者的資訊全部改為大寫後儲存/tmp/maxuser.txt檔案中

sort -t: -k3 -n  passwd | tail -n 10 | tr ‘a-z‘ ‘A-Z‘ > /tmp/maxuser.txt


5、取出當前主機的IP地址,提示:對ifconfig命令的結果進行切分

ifconfig | grep  "inet\b" | tr -s ‘ ‘ ‘#‘ | cut -d# -f3


6、列出/etc目錄下所有以.conf結尾檔案的檔案名稱,並將其名字轉換為大寫後儲存至/tmp/etc.conf檔案中

ls /etc/*.conf | tr ‘a-z‘ ‘A-Z‘ > /tmp/etc.conf


7、顯示/var/目錄下一級子目錄或檔案的總個數

ls /var/ | wc -l


8、將/etc/group檔案中第三個欄位數值最小的10個組的名字

cat /etc/group | sort -t: -k3 -n | head -n 10 | cut -d: -f1


9、取出/etc/fstab和/etc/issue檔案的內容合并為同一個內容儲存至/tmp/etc.test檔案中

cat /etc/{fstab,issue} >> /tmp/etc.test


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添加密碼,密碼為magedu

echo "magedu" | passwd --stdin mageia


(5)、刪除mandriva,但保留其家目錄;

userdel mandriva


(6)、建立使用者slackware,其ID號為2002,基本組為distro,附加組peguin;

useradd -u 2002 -g distro -G peguin slackware


(7)、修改slackware的預設shell為/bin/tcsh;

usermod -s /bin/tcsh slackware


(8)、為使用者slackware新增附加組admins;

groupadd admins

usermod -G admins slackware


(9)、為slackware添加密碼,且要求密碼最短使用到期日為3天,最長為180天,警告為3天;

echo "123" | passwd -n 3 -x 180 -w 3 --stdin slackware


(10)、添加使用者openstack,其ID號為3003, 基本組為clouds,附加組為peguin和nova;

useradd -u 3003 -g clouds -G peguin,nova openstack


(11)、添加系統使用者mysql,要求其shell為/sbin/nologin;

useradd -r mysql -s /sbin/nologin


(12)、使用echo命令,非互動式為openstack添加密碼。

echo 123 | passwd --stdin openstack


本文出自 “linux” 部落格,請務必保留此出處http://001230.blog.51cto.com/11559496/1887380

作業練習:3

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.