User Tools

Site Tools


os:find
Return to Home page

Differences

This shows you the differences between two versions of the page.


os:find [2024/04/08 22:35] (current) – created - external edit 127.0.0.1
Line 1: Line 1:
 +====== The find command ======
 +Return to [[os:|Operating Systems Course]]
 +
 +<html>
 +<iframe width="560" height="315" src="https://www.youtube.com/embed/MfortwrrofU" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
 +</html>
 +
 +Examples about the ''find'' Linux command
 +
 +  * Find all the files, starting from the current working directory and using the ''-name'' option with name ''aBcBa.txt''
 +<code bash>
 +find . -name "aBcBa.txt"
 +</code>
 +
 +  * Find, using the ''-regex'' option, if the current working directory contains a file with name ''aBcBa.txt''
 +<code bash>
 +find . -regex "\./aBcBa.txt"
 +</code>
 +
 +  * Find all the files, starting from the current working directory and using the ''-regex'' option with name ''aBcBa.txt''
 +<code bash>
 +find . -regex ".*/aBcBa.txt"
 +</code>
 +
 +  * Find all the regular files in the current working directory whose name starts with an ''A'' or with an ''a'', followed by one character, followed by and ''A'' or an ''a'', followed by a sequence of characters, and terminated with the extension ''.txt''
 +<code bash>
 +find . -type f -iname "a?a*.txt"
 +find . -type f -regex ".*/[aA].[aA][^/]*\.txt"
 +</code>
 +
 +  * Find all the regular files starting from the parent of the current working directory, whose name contains two lower case ''a'' separate by ''a'' character, eventually proceeded and followed by a sequence of characters and with extension ''.txt'' (e.g., ''aaa.txt'', ''axa.txt'', ''123axa.txt'', ''axa123.txt'', ''123axa456.txt'')
 +<code bash>
 +find . -type f -regex ".*a.a[^/]*\.txt"
 +</code>
 +
 +  * Find all the regular files starting from the home directory which have not the ''777'' permissions:
 +<code bash>
 +find ~ -type f ! -perm 777
 +</code>
 +
 +  * Find all the directories starting from the root of the file system which have the ''777'' permissions, and change their permission in ''755'':
 +<code bash>
 +find / -type d -perm 777 -exec chmod 755 \{} \;
 +</code>
 +
 +  * Find all the regular files starting from the current working directory whose name has extension .txt, and remove then
 +<code bash>
 +find . -type f -name "*.txt" -exec rm -f \{} \;
 +</code>
 +
 +  * Find all the regular files starting from the ''/tmp'' directory that are //empty//
 +<code bash>
 +find /tmp -type f -empty
 +</code>
 +
 +  * Find all the elements starting from the current working directory, whose name is ''x.txt'' or ''y.txt''
 +<code bash>
 +find . -regextype posix-extended -regex ".*/(x|y).txt"
 +</code>
 +
 +  * Find all the elements starting from the directory ''/home'' owned by the user ''stefano'' whose name has extension ''.txt''
 +<code bash>
 +find /home -user stefano -iname "*.txt"
 +</code>
 +
 +  * Find all the elements starting from the directory ''/home'' owned by the group ''developer''
 +<code bash>
 +find /home -group developer
 +</code>
 +
 +  * Find all the elements starting from the root of the file system with size greater than 50 Megabytes and lower than 100 Megabytes
 +<code bash>
 +find / -size +50M -size -100M
 +</code>
 +
 +  * Find all the regular files starting from the root of the file system whose name has extension ''.mp3'' and their size is greater than 10 Megabytes, and remove them
 +<code bash>
 +find / -type f -name "*.mp3" -size +10M -exec rm \{} \;
 +</code>
 +
 +  * Find all the regular files starting from the current working directory, whose name has extension ''.c'' //or// ''.sh''
 +<code bash>
 +find . -type f \( -name "*.c" -o -name "*.sh" \)
 +</code>
 +
 +  * Find all the regular files starting from the current working directory, whose name finishes with the string ''cache'' //or// ''xml'' //or// ''html''
 +<code bash>
 +find . -type f \( -name "*cache" -o -name "*xml" -o -name "*html" \) 
 +</code>
 +
 +  * Find all the elements in the home directory with the modification date more recent than 1440 minutes (one day)
 +<code bash>
 +find ~ -mmin -1440
 +</code>
 +
 +  * Find all the elements in the home directory with the modification date more recent than one day (as previous command)
 +<code bash>
 +find ~ -mtime -1
 +</code>
 +
 +  * Find all the elements in the home directory with the modification date between 10 and 14 days
 +<code bash>
 +find ~ -type f -mtime +10 -mtime -14
 +</code>
  

If you found any error, or if you want to partecipate to the editing of this wiki, please contact: admin [at] skenz.it

You can reuse, distribute or modify the content of this page, but you must cite in any document (or webpage) this url: https://www.skenz.it/os/find?do=diff&rev2%5B0%5D=1573835417&rev2%5B1%5D=1574111352&difftype=sidebyside
/web/htdocs/www.skenz.it/home/data/pages/os/find.txt · Last modified: 2024/04/08 22:35 by 127.0.0.1

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki
Privacy Policy