Return to Operating Systems Course
Examples about the find
Linux command
-name
option with name aBcBa.txt
find . -name "aBcBa.txt"
-regex
option, if the current working directory contains a file with name aBcBa.txt
find . -regex "\./aBcBa.txt"
-regex
option with name aBcBa.txt
find . -regex ".*/aBcBa.txt"
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
find . -type f -iname "a?a*.txt" find . -type f -regex ".*/[aA].[aA][^/]*\.txt"
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
)find . -type f -regex ".*a.a[^/]*\.txt"
777
permissions:find ~ -type f ! -perm 777
777
permissions, and change their permission in 755
:find / -type d -perm 777 -exec chmod 755 \{} \;
find . -type f -name "*.txt" -exec rm -f \{} \;
/tmp
directory that are emptyfind /tmp -type f -empty
x.txt
or y.txt
find . -regextype posix-extended -regex ".*/(x|y).txt"
/home
owned by the user stefano
whose name has extension .txt
find /home -user stefano -iname "*.txt"
/home
owned by the group developer
find /home -group developer
find / -size +50M -size -100M
.mp3
and their size is greater than 10 Megabytes, and remove themfind / -type f -name "*.mp3" -size +10M -exec rm \{} \;
.c
or .sh
find . -type f \( -name "*.c" -o -name "*.sh" \)
cache
or xml
or html
find . -type f \( -name "*cache" -o -name "*xml" -o -name "*html" \)
find ~ -mmin -1440
find ~ -mtime -1
find ~ -type f -mtime +10 -mtime -14