Low Orbit Flux Logo 2 F

Linux Command - find



find

find /path/to/search -name "file.txt"
find . -name "*.log"
find . -iname "*.jpg"   # case insensitive

find /usr -name themes
find /usr -name *.png

Find by type:



find . -type f        # Regular files
find . -type d        # Directories
find . -type l        # Symbolic links

By size:



find . -size +100M        # Files larger than 100 MB
find /var/log -size -1M   # Smaller than 1 MB
find . -size 10k          # Exactly 10 KB

c bytes
k KB
M MB
G GB

By time:



find /var/log -mtime -1      # Modified in the last 1 day
find /var/log -mtime +7      # Modified more than 7 days ago
find /var/log -mmin -30      # Modified in the last 30 minutes
find /var/log -atime +10  # Accessed more than 10 days ago

-mtime modification time (in days)
-mmin modification time (in minutes)
-atime last access time
-ctime metadata/status change time

Find by owner or permissions:



find . -perm 644
find . -perm -u+x        # Files the owner can execute
find / -user root        # Owned by root
find . -group developers # Belonging to a group

Multiple conditions, logic, and xargs:



find /var -type f -name "*.log" -size +10M               # multiple conditions
find /usr -type f \( -name "*.jpg" -or -name "*.png" \)  # OR
find / -type f ! -user root                              # not
find /var -type f -name "*.log" | xargs grep "error"     # xargs

Using exec:



find . -type f -name "*.bak" -exec ls -lh {} \;  # exec ls
find . -type f -name "*.bak" -exec rm -v {} \;   # exec rm