标题:
unix 的 find 命令
[打印本页]
作者:
51黑tt
时间:
2016-3-6 15:11
标题:
unix 的 find 命令
bash-2.05b$ find $shell_learn -name *.* -exec rm {} \;
-exec:当执行到-exec 后的命令时,{} 将被搜索结果所代替
-ok: 会询问是否作给出的操作
bash-2.05b$ find . -name *.h -ok rm {} \;
< rm ... ./mgr/AccGxMgnt.h > ? n
< rm ... ./pmgr/OpenBossApp.h > ? n
< rm ... ./pmgr/AccGxMgnt.h > ? n
< rm ... ./pmgr/AccGxMgnt_pmgr_obd_i.h > ?
发现了find -o选项查找顺序是倒着来的
bash-2.05b$ find . -name '*.o' -o -name '*.so' -o -name 'AccTranBil' -exec ls {} \;
./app/build/AccTranBil
bash-2.05b$ find . -name '*.o' -o -name '*.so' -exec ls {} \;
./app/build/libAccTranBil_appD.so
./kernel/build/libAccTranBil_dbD.so
./mgr/build/libAccTranBil_mgrD.so
./pmgr/build/libAccTranBil_pmgrD.so
bash-2.05b$
这个例子完全是个错的,误人子弟啊,删掉一种就停了。
bash-2.05b$ find . -name '*.o' -o -name '*.so' -o -name 'AccTranBil' -exec ls {} \;
网上搜了几个例子
bash-2.05b$ find $HOME/. -name *.txt -ok ls {} \;
< ls ... /home/BOSS/liu/./.subversion/README.txt > ? n
或
bash-2.05b$ find . $HOME -name *.txt -exec ls {} \;
find命令是功能最强的命令之一,但同时也是命令行结构最难以掌握的命令之一。
# find ./ -print 打印当前目录下所有文件
#find ./ |wc -l 显示当前目录下的文件数目
# find ./ -user $LOGNAME -print 显示当前目录登陆用户所有文件和目录。
# find ./ -size 0-print 显示文件大小为0 的blocks
bash-2.05b$ find . -size 0 -print
./pmgr/.svn/text-base/AccGxMgnt.h.svn-base
./pmgr/AccGxMgnt.h
./1
# find ./ -size -100 -print 显示文件大小小于100 的blocks 。
# find ./ -size +100 -print 显示文件大小大于100 的 blocks 。
bash-2.05b$ find . -name "core" -exec rm {} \;;查找并删除core文件。
# find . -exec chown $LOGNAME {} \; 修改一个目录下的所有文件的用户所属
# find .-type d -exec chmod 770 {} \;修改一个目录下的所有目录的权限
-type Type
Evaluates to the value True if the Type variable specifies one of the following values:
b
Block special file
c
Character special file
d
Directory
f
Plain file
l
Symbolic link
p
FIFO (a named pipe)
s
Socket
bash-2.05b$ find . -type d -exec chmod 770 {} \;
bash-2.05b$ ls -al
total 64
drwxrwx--- 11 ng_liuy NG_BOSS 4096 Sep 1 17:50 ./
drwxr-xr-x 95 ng_liuy NG_BOSS 4096 Sep 1 16:58 ../
drwxrwx--- 6 ng_liuy NG_BOSS 4096 Sep 1 17:36 .svn/
-rw-r--r-- 1 ng_liuy NG_BOSS 0 Sep 1 17:48 1
-rw-r--r-- 1 ng_liuy NG_BOSS 68 Aug 24 15:29 Makefile
drwxrwx--- 3 ng_liuy NG_BOSS 256 Aug 25 10:15 app/
drwxrwx--- 3 ng_liuy NG_BOSS 4096 Aug 24 11:35 include/
drwxrwx--- 3 ng_liuy NG_BOSS 256 Aug 24 11:35 kernel/
drwxrwx--- 3 ng_liuy NG_BOSS 256 Aug 24 11:35 mgr/
drwxrwx--- 3 ng_liuy NG_BOSS 4096 Aug 24 11:35 pmgr/
drwxrwx--- 3 ng_liuy NG_BOSS 4096 Sep 1 14:27 public_src/
drwxrwx--- 3 ng_liuy NG_BOSS 256 Aug 24 11:35 svr/
drwxrwx--- 3 ng_liuy NG_BOSS 256 Aug 24 11:35 test/
-rw-r--r-- 1 ng_liuy NG_BOSS 1 Sep 1 17:48 x
欢迎光临 (http://www.51hei.com/bbs/)
Powered by Discuz! X3.1