# Finding files by name
find ~ -name "fix*" -print
# Finding files by type
find Documents -name junk* -type f -print
# To find a symbolic link, use "-type l"
find . -name "h*" -type l -ls
# Remove all files older than n days in current folder
find . -type f -mtime +n | xargs rm
# delete files (including subdirectories)
find ~ -name *.old -exec rm {} \;
find . -name *.old -ok rm {} \; # `-ok` ask for approval before removing the files. Answering y for “yes” would allow the find command to go ahead and remove the files one by one.
find . -name runme -okdir rm {} \; # use the `-okdir` option. Like `-ok`, this option will prompt for permission to run the command
# Finding files by owner and/or group
find . -user www-data -ls | head -4
find . -user 1000 -ls | head -4
find /tmp -user shs -ls 2> /dev/null
find /home -group tom -print
find /tmp -group 1000 -ls 2>/dev/null
# Finding files by file permissions
find /usr/bin -name "net*" -perm -g=w -ls
find /usr/bin -name "d*" -perm 777 -ls | head -3
# Finding files by age
# +100 (more than 100 days old) or -10 (modified within the last 10 days)
find Documents -mtime -1
# Finding files by size
find . -size 0 -ls | head -1 # this find empty files
find . -size 0 -ls | wc -l # this command would find a lot more empty files – representing the cache and such
find / -type f -size +1G -ls 2>/dev/null # finds files that are larger than 1 GB: Notice that the command sends all the “permission denied” messages to the /dev/null.
# `-execdir` runs the specified command from the directory in which the located file resides rather than from the directory in which the find command is run
find . -name runme -execdir pwd \;
/home/shs/bin
# If you run the command shown below and the directory contains a file named “ls”, it will run that file and it will run it even if the file does not have execute permissions set
find . -name runme -execdir ls \;
Running the /home/shs/bin/ls file