Linux Command Exercise

2296 ワード

Ex01

/etc/passwdファイルの14行目から17行目までをコロンで区切り、これらの情報を3番目のフィールドの数値サイズで並べ替え、最後に表示されるそれぞれの1番目のフィールドのみ
[root@Study ~]# cat -n /etc/passwd | head -n 17 | tail -n +14 | sort -t: -k3 -n | cut -d: -f1
    14  ftp
    17  vcsa
    16  dbus
    15  nobody
[root@Study ~]# cat -n /etc/passwd | sed -n '14,17p' | sort -t: -k3 -n | cut -d: -f1
    14  ftp
    17  vcsa
    16  dbus
    15  nobody

Ex02


ユーザーgentooが作成され、追加グループはdistroおよびlinux、デフォルトshellは/bin/csh、注釈情報は"Gentoo Distribution"です.
[root@Study ~]# useradd -G distro,linux -c "Gentoo Distribution" -s /bin/csh gentoo
[root@Study ~]# id gentoo
uid=500(gentoo) gid=502(gentoo) groups=502(gentoo),500(distro),501(linux)
[root@Study ~]# tail -n 1 /etc/passwd
gentoo:x:500:502:Gentoo Distribution:/home/gentoo:/bin/csh
[root@Study ~]# tail -n 3 /etc/group
distro:x:500:gentoo
linux:x:501:gentoo
gentoo:x:502:

Ex03

/etc/passwdファイルの最初の5行の内容を大文字に変換して/tmp/passwd.outファイルに保存
[root@Study ~]# cat -n /etc/passwd | head -n 5 | tr 'a-z' 'A-Z' | tee /tmp/passwd.out
     1  ROOT:X:0:0:ROOT:/ROOT:/BIN/BASH
     2  BIN:X:1:1:BIN:/BIN:/SBIN/NOLOGIN
     3  DAEMON:X:2:2:DAEMON:/SBIN:/SBIN/NOLOGIN
     4  ADM:X:3:4:ADM:/VAR/ADM:/SBIN/NOLOGIN
     5  LP:X:4:7:LP:/VAR/SPOOL/LPD:/SBIN/NOLOGIN
[root@Study ~]# cat /tmp/passwd.out 
     1  ROOT:X:0:0:ROOT:/ROOT:/BIN/BASH
     2  BIN:X:1:1:BIN:/BIN:/SBIN/NOLOGIN
     3  DAEMON:X:2:2:DAEMON:/SBIN:/SBIN/NOLOGIN
     4  ADM:X:3:4:ADM:/VAR/ADM:/SBIN/NOLOGIN
     5  LP:X:4:7:LP:/VAR/SPOOL/LPD:/SBIN/NOLOGIN

Ex04


前システム上のユーザ情報の後3行に登録した情報を大文字に変換して/tmp/who.outファイルに保存する
[root@Study ~]# who | tail -n 3 | tr 'a-z' 'A-Z' | tee /tmp/who.out 
ROOT     TTY1         2017-11-04 18:03
ROOT     PTS/0        2017-11-04 15:23 (192.168.1.114)
ROOT     PTS/1        2017-11-04 18:02 (192.168.1.114)
[root@Study ~]# cat /tmp/who.out 
ROOT     TTY1         2017-11-04 18:03
ROOT     PTS/0        2017-11-04 15:23 (192.168.1.114)
ROOT     PTS/1        2017-11-04 18:02 (192.168.1.114)