找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

搜索
查看: 1612|回復: 0
打印 上一主題 下一主題
收起左側

unix 的 find 命令

[復制鏈接]
跳轉(zhuǎn)到指定樓層
樓主
ID:107189 發(fā)表于 2016-3-6 15:11 | 只看該作者 回帖獎勵 |倒序瀏覽 |閱讀模式


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


分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏 分享淘帖 頂 踩
回復

使用道具 舉報

您需要登錄后才可以回帖 登錄 | 立即注冊

本版積分規(guī)則

小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術交流QQ群281945664

Powered by 單片機教程網(wǎng)

快速回復 返回頂部 返回列表