码迷,mamicode.com
首页 > 系统相关 > 详细

Linux管道及IO重定向小练习

时间:2014-05-21 02:01:09      阅读:530      评论:0      收藏:0      [点我收藏+]

标签:linux   管道   io重定向   

1.统计/usr/bin目录下的文件个数

[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目录下每个文件的内容类型?

[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行

[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文件中

[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开头的文件,并统计其个数

[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文件中

[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的重要哲学思想:

组合小命令完成复杂功能。












本文出自 “我想超越自我” 博客,请务必保留此出处http://zhangfengzhe.blog.51cto.com/8855103/1413214

Linux管道及IO重定向小练习,布布扣,bubuko.com

Linux管道及IO重定向小练习

标签:linux   管道   io重定向   

原文地址:http://zhangfengzhe.blog.51cto.com/8855103/1413214

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!