Sometimes it is critical to quickly find the desired file or information on the system. Sometimes you can limit yourself to the standard search functions that any file manager now has, but they cannot compare with the capabilities of the terminal.
find β , , :
- .
- .
- .
:
- .
- .
- .
find Linux .
find:
$ find directory-to-search criteria action
:
- directory-to-search ( ) β , find , . , ;
- criteria () β , ;
- action () β , .
s.txt :
$ find . -name "s.txt"
./s.txt
:
- . () β
- -name β . .
-name S.txt . βiname.
$ find . -iname "s.txt"
./s.txt
./S.txt
c .png *.png:
$ find . -name "*.png"
./babutafb.png
./babutafacebook.png
./Moodle2.png
./moodle.png
./moodle/moodle1.png
./genxfacebook.png
. , find png home:
$ find /home -name "*.png"
find: `/home/babuta/.ssh': Permission denied
/home/vagrant/Moodle2.png
/home/vagrant/moodle.png
/home/tisha/hello.png
find: `/home/tisha/testfiles': Permission denied
find: `/home/tisha/data': Permission denied
/home/tisha/water.png
find: `/home/tisha/.cache': Permission denied
, β 2> /dev/null. dev/null, .
find /home -name "*.jpg" 2>/dev/null
/home/vagrant/Moodle2.jpg
/home/vagrant/moodle.jpg
/home/tisha/hello.jpg
/home/tisha/water.jpg
-type , :
- f β ;
- d β ;
- l β ;
- b β (dev);
- c β (dev);
- p β ;
- s β ;
, -type d :
$ find . -type d
.
./.ssh
./.cache
./moodle
, . -size.
- "+" β
- "-" β
- , .
1 (+1G).
$ find . -size +1G
./Microsoft_Office_16.29.19090802_Installer.pkg
./android-studio-ide-183.5692245-mac.dmg
:
- c β
- k β
- M β
- G β
-empty .
$ find . -empty
./.cloud-locale-test.skip
./datafiles
./b.txt
...
./.cache/motd.legal-displayed
-cmin . , ( 60 ), -60:
$ find . -cmin -60
.
./a.txt
./datafiles
, ( 60 ).
, +60.
$ find . -cmin +60
-atime .
$ find . -atime +180
, (180 ).
βuser username , :
$ find /home -user tisha 2>/dev/null
tisha home, 2>/dev/null .
-perm β .
$ find /home -perm 777
777.
:
- -and
- -or
- -not
, 1 tisha :
$ find /home -user tisha -and -size +1G 2>/dev/null
tisha, pokeristo, 1 .
$ find /home \( -user pokeristo -or -user tisha \) -and -size +1G 2>/dev/null
"\".
find , .
- -delete β
- -ls β :
- .
- inode.
- -print , . .
- -exec .
-delete
, , :
$ find . -empty -delete
. -print.
-exec:
.
-exec command {} \;
:
- command β , . :
- rm
- mv
- cp
- {} β .
- \; β .
βexec βdelete :
$ find . -empty -exec rm {} \;
-exec:
$ find . -name "*.jpg" -exec cp {} /backups/fotos \;
.jpg backups/fotos
find :
- .
- .
- .
- ( ).
- .
- .
- .
- .
, :
- .
- .
- .
find , β .