Linux管道及IO重定向小練習

1.統計/usr/bin目錄下的文件個數bash

[root@localhost ~]# ls /usr/bin | wc -l
1306
[root@localhost ~]#


2.取出當前系統上全部用戶的SHELL,要求,每種SHELL只顯示一次,而且按順序進行顯示編輯器

[root@localhost ~]# cut -d: -f7 /etc/passwd | sort -u
/bin/bash
/bin/nologin
/bin/sync
/bin/tcsh
/sbin/halt
/sbin/login
/sbin/nologin
/sbin/shutdown
[root@localhost ~]#


3.思考:如何顯示/var/log目錄下每一個文件的內容類型?ide

[root@localhost ~]# file /var/log/*
/var/log/acpid:            ASCII text
/var/log/anaconda.log:     ASCII English text, with very long lines
/var/log/anaconda.syslog:  ASCII English text
/var/log/anaconda.xlog:    ASCII English text
/var/log/audit:            directory
/var/log/boot.log:         empty
/var/log/boot.log.1:       empty
/var/log/boot.log.2:       empty
/var/log/boot.log.3:       empty
/var/log/boot.log.4:       empty


4.取出/etc/inittab文件的第6行ui

[root@localhost ~]# head -6 /etc/inittab
#
# inittab       This file describes how the INIT process should set up
#               the system in a certain run-level.
#
# Author:       Miquel van Smoorenburg, <miquels@drinkel.nl.mugnet.org>
#               Modified for RHS Linux by Marc Ewing and Donnie Barnes
[root@localhost ~]# head -6 /etc/inittab | tail -1
#               Modified for RHS Linux by Marc Ewing and Donnie Barnes
[root@localhost ~]#


5.取出/etc/passwd文件中倒數第9個用戶的用戶名和SHELL,顯示到屏幕上並將其保存至/tmp/uses文件中it

[root@localhost ~]# tail -9 /etc/passwd
zhangfengzhe10:x:1102:1102::/home/zhangfengzhe10:/bin/bash
zhangfengzhe11:x:1103:1103::/home/zhangfengzhe11:/sbin/nologin
zhangfengzheforsys:x:101:102::/home/zhangfengzheforsys:/bin/bash
test1:x:1104:1104::/home/test1:/bin/bash
mandriva:x:4004:3004::/home/mandriva:/bin/bash
fedora:x:2003:2003:Fedora Commnuity:/home/fedora:/bin/tcsh
hbase:x:102:103::/home/hbase:/bin/nologin
openstack:x:4005:4005::/home/openstack:/bin/bash
hive:x:5000:5000::/home/hive:/bin/bash
[root@localhost ~]# tail -9 /etc/passwd | head -1
zhangfengzhe10:x:1102:1102::/home/zhangfengzhe10:/bin/bash
[root@localhost ~]# tail -9 /etc/passwd | head -1 | cut -d: -f1,7
zhangfengzhe10:/bin/bash
[root@localhost ~]# tail -9 /etc/passwd | head -1 | cut -d: -f1,7 | tee /tmp/users
zhangfengzhe10:/bin/bash
[root@localhost ~]# cat /tmp/users
zhangfengzhe10:/bin/bash
[root@localhost ~]#


6.顯示/etc目錄下全部以pa開頭的文件,並統計其個數
io

[root@localhost ~]# ls -ld /etc/pa*/
drwxr-xr-x 2 root root 4096 Mar  5  2012 /etc/pam.d/
drwxr-xr-x 2 root root 4096 Aug 17  2011 /etc/pam_pkcs11/
drwxr-xr-x 3 root root 4096 Aug 17  2011 /etc/pango/
[root@localhost ~]# ls -ld /etc/pa*/ | wc -l
3
[root@localhost ~]#


7.不使用文本編輯器,將alias cls=clear一行內容添加至當前用戶的.bashrc文件中table

[root@localhost ~]# echo "alias cls='clear'"
alias cls='clear'
[root@localhost ~]# echo "alias cls='clear'" >> ~/.bashrc
[root@localhost ~]# tail -1 ~/.bashrc
alias cls='clear'
[root@localhost ~]# tail  ~/.bashrc
alias cp='cp -i'
alias mv='mv -i'
# Source global definitions
if [ -f /etc/bashrc ]; then
    . /etc/bashrc
fi
alias cls='clear'
[root@localhost ~]#


LINUX的重要哲學思想:class

組合小命令完成複雜功能。
test

相關文章
相關標籤/搜索