查找
find、locate、grep等
1)根据文件属性信息查找
find:系统中存在的文件,时间长、效率低
locate:不存在于库查不到
效率快
updatedb更新数据库
locate 文件名称
[root@bogon home]# find /home -namefile5
/home/file5
[root@bogon home]# locate file5
[root@bogon home]# updatedb
find:在指定的路径下查找文件
语法:find 路径 条件 模式
确定命令位置
/bin/ls
whereis find
man---manual 1
-name:表示按照文件名查找
-type:按照文件类型查找
-exec:将查找结果进行二次处理
[root@bogon home]# find /home -name file -type d -exec rm -r {}\;
将/home下所有的file目录删除,
练习:查找linux系统中c语言的源文件
[root@bogon dir4]# cd /home
[root@bogon home]# find / -name *.c
find: /proc/2801/fd: 没有那个文件或目录
find: /proc/2804/fd: 没有那个文件或目录
/tmp/vmware-tools-distrib/lib/GuestSDK/vmGuestLibTest.c
/usr/lib/openoffice/program/addin/source/xdfa.c
[root@bogon home]# find /home -name file1
[root@bogon home]# find /home -name file1
[root@bogon home]# ls
dir1 dir2 dir3 dir4 file file2 file3
[root@bogon home]# find /home -name file
/home/file
[root@bogon home]# find /home -name file*
find: paths must precede expression
Usage: find [path...] [expression]
[root@bogon home]# find / -name file -type d
find: /proc/2801/fd: 没有那个文件或目录
find: /proc/2804/fd: 没有那个文件或目录
/usr/lib/perl5/vendor_perl/5.8.0/URI/file
2)根据文件内容查找
3)grep
查找/etc/passwd文件中含有root的行的数量
[root@bogon home]# grep -c root /etc/passwd
2
[root@bogon home]# grep sh$/etc/passwd
|:管道符号
ctrl+D:强制终止输入操作
[root@bogonhome]# cat
adfdfasdfdgafag
adfdfasdfdgafag
[root@bogon home]# cat >file
1233
ssddd
asdff
[root@bogon home]# cat file
1233
ssddd
asdff
[root@bogonhome]# tr -s a A
apple
Apple
[root@bogon home]# tr -d this
tabcd
abcd
ahbcd
abcd
[root@bogon home]# date
四 12月 8 10:43:50 CST 2011
[root@bogonhome]# date |cut -f 1 -d " "
四
[root@bogonhome]# date |cut -f 2 -d " "
12月
[root@bogonhome]# date |cut -f 6 -d " "
CST
[root@bogonhome]# date |cut -f 1,2,4 -d ""
四 12月 8
[root@bogonhome]# date |cut -f 2,4,7 -d ""
12月 8 2011
[root@bogonhome]# date |cut -f 2-7 -d " "
12月 8 10:48:56 CST 2011
获取年月日,并按照“年-月-日”显示
[root@bogon home]# date |cut-f 2,4,7 -d " " | tr -s " " -
12月-8-2011