課程
/運維&測試
/Linux
/Linux權限管理之特殊權限
感覺這個腳本不對,然后能說出每一行的意思嗎?麻煩給出正確的答案,感謝!
2016-10-07
源自:Linux權限管理之特殊權限 1-2
正在回答
使用一條find命令就可以了
find /usr/local/test/ -size +100k -exec mv {} /tmp \;
如果只需要移動文件不移動目錄,find /usr/local/test/ -size +100k -type f -exec mv {} /tmp \;
Motoc16 提問者
掌上觀石 回復 Motoc16 提問者
你用的手機吧,用大點的例如平板,或者電腦顯示器,分辨率高的顯示的清。怎么學習?怎么看視頻啊?
如果不允許使用find,必須用腳本實現:
#!/bin/bash
ls?-al?/usr/local/test?>?./temp.txt??#將目錄中的ls信息輸出到temp.txt touch?1.txt?move2tmp.txt???#創建兩個文件備用 sed?'s/[[:space:]]\+/\*/g'?./temp.txt?>?1.txt??#將文件文本中的單個或連續空格替換為*,備用 for?i?in?`cat?1.txt`;do ????????declare?-i?size=`echo?$i?|?awk?-F'*'?'{print?$5}'`???#通過*分割每一行中的內容?取出第五個字段(文件大小),也可以用cut?-d ????????if?[?$size?-gt?100000?];then ????????????????filename=`echo?$i?|?awk?-F'*'?'{print?$NF}'`??#如果大小大于100k,取得其文件名 ????????????????mv?$filename?/tmp???#將該文件移到tmp目錄下 ????????????????echo?$filename>>move2tmp.txt???#記錄移動的文件 ????????else ????????????????continue ????????fi done rm?-f?1.txt?biglog.txt?temp.txt??#刪除用過的臨時文件,保留文件移動移動記錄move2tmp.txt
用find命令是個好方法,這里學習了,
不過如果是僅僅查找/usr/local/test目錄而不查找其內的字目錄的話,則不建議用find命令,因為find命令是在目錄結構中搜索文件和目錄,并執行指定的操作,也就是說find會對目錄內的所有文件和目錄及其字目錄進行全部搜索,則如樓上所說的用find則會對/usr/local/test目錄及其字目錄字字目錄都進行查找出大于100k的文件然后都進行移動到/tmp。
舉例如下,
[root@rhel7 test]# ll -h
total 1.5M
drwxr-xr-x. 3 root root ? 61 Feb 13 20:56 abrt
-rw-r--r--. 1 root root ?32K Feb 13 20:43 meta.db-shm
-rw-r--r--. 1 root root 1.4M Feb 13 20:43 meta.db-wal
drwxr-xr-x. 2 root root 4.0K Feb 13 20:43 tracker
[root@rhel7 test]# find ./ -size 100k
[root@rhel7 test]# find ./ -size 100k -type f
[root@rhel7 test]# find ./ -size 100k -type f -pint
find: unknown predicate `-pint'
[root@rhel7 test]# find ./ -size 100k -type f -print
[root@rhel7 test]# find ./ -size +100k -type f
./meta.db-wal
./tracker/meta.db
./tracker/meta.db-wal
./tracker/ontologies.gvdb
舉報
本Linux教程一定會讓你對Linux中的權限有更深刻的認識
1 回答關于SUID的shell腳本
1 回答suid 的shell 腳本
1 回答為什么有的目錄權限后面有個點,有的目錄沒有
1 回答SGIT對目錄權限
1 回答請問文件和目錄的默認mask是在哪里可以改嗎?
Copyright ? 2025 imooc.com All Rights Reserved | 京ICP備12003892號-11 京公網安備11010802030151號
購課補貼聯系客服咨詢優惠詳情
慕課網APP您的移動學習伙伴
掃描二維碼關注慕課網微信公眾號
2016-10-08
使用一條find命令就可以了
find /usr/local/test/ -size +100k -exec mv {} /tmp \;
如果只需要移動文件不移動目錄,find /usr/local/test/ -size +100k -type f -exec mv {} /tmp \;
2022-03-27
你用的手機吧,用大點的例如平板,或者電腦顯示器,分辨率高的顯示的清。怎么學習?怎么看視頻啊?
2020-08-27
2017-02-13
用find命令是個好方法,這里學習了,
不過如果是僅僅查找/usr/local/test目錄而不查找其內的字目錄的話,則不建議用find命令,因為find命令是在目錄結構中搜索文件和目錄,并執行指定的操作,也就是說find會對目錄內的所有文件和目錄及其字目錄進行全部搜索,則如樓上所說的用find則會對/usr/local/test目錄及其字目錄字字目錄都進行查找出大于100k的文件然后都進行移動到/tmp。
舉例如下,
[root@rhel7 test]# ll -h
total 1.5M
drwxr-xr-x. 3 root root ? 61 Feb 13 20:56 abrt
-rw-r--r--. 1 root root ?32K Feb 13 20:43 meta.db-shm
-rw-r--r--. 1 root root 1.4M Feb 13 20:43 meta.db-wal
drwxr-xr-x. 2 root root 4.0K Feb 13 20:43 tracker
[root@rhel7 test]# find ./ -size 100k
[root@rhel7 test]# find ./ -size 100k -type f
[root@rhel7 test]# find ./ -size 100k -type f -pint
find: unknown predicate `-pint'
[root@rhel7 test]# find ./ -size 100k -type f -print
[root@rhel7 test]# find ./ -size +100k -type f
./meta.db-wal
./tracker/meta.db
./tracker/meta.db-wal
./tracker/ontologies.gvdb