標題:
unix 的 find 命令
[打印本頁]
作者:
51黑tt
時間:
2016-3-6 15:11
標題:
unix 的 find 命令
bash-2.05b$ find $shell_learn -name *.* -exec rm {} \;
-exec:當執(zhí)行到-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 > ?
發(fā)現(xiàn)了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 {} \;
網(wǎng)上搜了幾個例子
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 顯示當前目錄下的文件數(shù)目
# 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.torrancerestoration.com/bbs/)
Powered by Discuz! X3.1