Linux find command is a powerful sysadmin tool



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 , – .



image




All Articles