sh 来自http://www.thegeekstuff.com/2009/03/15-practical-linux-find-command-examples/

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了sh 来自http://www.thegeekstuff.com/2009/03/15-practical-linux-find-command-examples/相关的知识,希望对你有一定的参考价值。

$ find . -type f -exec ls -s {} \; | sort -n -r | head -5
$ find ~ -empty

$ find . -maxdepth 1 -empty

$ find . -maxdepth 1 -empty -not -name ".*"
$ ls -l
total 0
-rwxrwxrwx 1 root root 0 2009-02-19 20:31 all_for_all
-rw-r--r-- 1 root root 0 2009-02-19 20:30 everybody_read
---------- 1 root root 0 2009-02-19 20:31 no_for_all
-rw------- 1 root root 0 2009-02-19 20:29 ordinary_file
-rw-r----- 1 root root 0 2009-02-19 20:27 others_can_also_read
----r----- 1 root root 0 2009-02-19 20:27 others_can_only_read


$ find . -perm -g=r -type f -exec ls -l {} \;
-rw-r--r-- 1 root root 0 2009-02-19 20:30 ./everybody_read
-rwxrwxrwx 1 root root 0 2009-02-19 20:31 ./all_for_all
----r----- 1 root root 0 2009-02-19 20:27 ./others_can_only_read
-rw-r----- 1 root root 0 2009-02-19 20:27 ./others_can_also_read


$ find . -perm g=r -type f -exec ls -l {} \;
----r----- 1 root root 0 2009-02-19 20:27 ./others_can_only_read


$ find . -perm 040 -type f -exec ls -l {} \;
----r----- 1 root root 0 2009-02-19 20:27 ./others_can_only_read
$ touch "test-file-name"

# touch "test-file-name "
[Note: There is a space at the end]

# ls -1 test*
test-file-name
test-file-name

$ ls -i1 test*
16187429 test-file-name
16187430 test-file-name

$ find -inum 16187430 -exec mv {} new-test-file-name \;

$ ls -i1 *test*
16187430 new-test-file-name
16187429 test-file-name

$ ls
file1.txt  file2.txt  file?.txt


$ find -inum 804180 -exec rm {} \;

# ls
file1.txt  file2.txt
[Note: The file with name "file?.txt" is now removed]



$ find -maxdepth 1 -not -iname "MyCProgram.c"
.
./MybashProgram.sh
./create_sample_files.sh
./backup
./Program.c
$ find -iname "MyCProgram.c" -exec md5sum {} \;
d41d8cd98f00b204e9800998ecf8427e  ./mycprogram.c
d41d8cd98f00b204e9800998ecf8427e  ./backup/mycprogram.c
d41d8cd98f00b204e9800998ecf8427e  ./backup/MyCProgram.c
d41d8cd98f00b204e9800998ecf8427e  ./MyCProgram.c
$ find / -name passwd
./usr/share/doc/nss_ldap-253/pam.d/passwd
./usr/bin/passwd
./etc/pam.d/passwd
./etc/passwd

$ find -maxdepth 2 -name passwd
./etc/passwd

$ find -mindepth 3 -maxdepth 5 -name passwd
./usr/bin/passwd
./etc/pam.d/passwd
$ find -iname "MyCProgram.c"
./mycprogram.c
./backup/mycprogram.c
./backup/MyCProgram.c
./MyCProgram.c
$ alias rm100m="find / -type f -name *.tar -size +100M -exec rm -i {} \;"
$ alias rm1g="find / -type f -name *.tar -size +1G -exec rm -i {} \;"
$ alias rm2g="find / -type f -name *.tar -size +2G -exec rm -i {} \;"
$ alias rm5g="find / -type f -name *.tar -size +5G -exec rm -i {} \;"

$ rm100m
$ rm1g
$ rm2g
$ rm5g
$ find / -type f -name *.zip -size +100M -exec rm -i {} \;"
$ alias rmao="find . -iname a.out -exec rm {} \;"
$ rmao


$ alias rmc="find . -iname core -exec rm {} \;"
$ rmc

$ find ~ -size +100M

$ find ~ -size -100M

$ find ~ -size 100M
$ ls -lrt
total 0
-rw-r----- 1 root root 0 2009-02-19 20:27 others_can_also_read
----r----- 1 root root 0 2009-02-19 20:27 others_can_only_read
-rw------- 1 root root 0 2009-02-19 20:29 ordinary_file
-rw-r--r-- 1 root root 0 2009-02-19 20:30 everybody_read
-rwxrwxrwx 1 root root 0 2009-02-19 20:31 all_for_all
---------- 1 root root 0 2009-02-19 20:31 no_for_all

$ find -newer ordinary_file
.
./everybody_read
./all_for_all
./no_for_all
$ find . -type s

$  find . -type d

$ find . -type f

$ find . -type f -name ".*"

$ find -type d -name ".*"
$ find . -type f -exec ls -s {} \; | sort -n  | head -5

$ find . -not -empty -type f -exec ls -s {} \; | sort -n  | head -5
$ find -name "MyCProgram.c"
./backup/MyCProgram.c
./MyCProgram.c

以上是关于sh 来自http://www.thegeekstuff.com/2009/03/15-practical-linux-find-command-examples/的主要内容,如果未能解决你的问题,请参考以下文章

sh 等待来自URL的200响应循环

sh 来自cacher

sh 来自env文件的Docker机密

sh 我的自卸车装载来自备份

sh 来自终端的快速提醒(bash)

如何使用来自 Java 文本字段的用户输入运行 .sh 脚本?