21 examples for find

{{ score }}
  # Executes a command on the files and folders matching a given pattern, in this case, output the last lines of each .foo file in the current folder and subfolders. 
find . -name "*.foo" -exec tail {} \;
        
{{ score }}
  # Outputs all the file names/paths that start with the name "Casey".  Searches recursively starting from my current directory (.)
# Throws out any error output by sending it to /dev/null 
find . -name "Casey*" 2>/dev/null
        
{{ score }}
  # Finds all files in and under the current directory that contain 'foo' in their name
find . -iname '*foo*'
        
{{ score }}
  # Searches entire computer starting at root for the file "hashClass.java".  Throws out error output by sending it to /dev/null.
# If we didn't throw out the error output, we'd get a bunch of "User doesn't have permissions to view directory" errors
find / -name "hashClass.java" 2>/dev/null
        
{{ score }}
  # directory -> chmod 700
# file executable -> chmod 700
# file -> chmod 600
# You can apply this to directory that needs more secure permission
# recursively. Like `~/.ssh`. `+` means run at once, not one by one. Like
# `xargs`.
find .private -type d -execdir chmod 700 '{}' + \
-or -type f -executable -execdir chmod 777 '{}' + \
-or -type f -execdir chmod 600 '{}' +
        
{{ score }}
  # Find and remove empty directories
find . -type d -empty -delete

# Find and remove empty files
find . -type f -empty -delete
        
{{ score }}
  # Find and remove files recursively starting in the current directory.
find . -name "FILE_TO_FIND" - exec rm -rf {} \;

# Especially useful for finding and removing temporary files.
# e.g. To remove compiled python files:
find . -name '*.pyc' -exec rm -rf {} \;
        
{{ score }}
  # Find files modified within a specific date range.
touch --date "2007-01-01" /tmp/start
touch --date "2008-01-01" /tmp/end
find /data/images -type f -newer /tmp/start -not -newer /tmp/end
        
{{ score }}
  # Find all files in home directory that does not match my user/group.
# Then change owner:group to my user/group.
find ~/ \( -not -group $(id -g) -or -not -user $USER \) -execdir chown $USER: '{}' +
        
{{ score }}
  # Find files that were modified less than 4 days ago and more than two days. Notice that `find -ctime +3 -ctime -4` would give no results.
find -ctime +2 -ctime -4
        
{{ score }}
  # Searches through my user's "home" directory recursively for the file "hashClass.java", throwing out error output along the way.  
# Passes the output to grep for case insensitive search.
find ~/ 2>/dev/null | grep -i "hashclass.java"
        
{{ score }}
  # Find all subdirectories that have been created in the last 5 days.
find . -type d -ctime -5
        
{{ score }}
  # find last modified file in current directory recursively except directory
find ./ -not -type d -printf "%T+ %p\n" | sort | tail -1
        
{{ score }}
  # Find broken symlinks
find -L . -type l
        
{{ score }}
  # Find all symlinks to specific file (GNU find)
find -L /dev -samefile /dev/video0
        
{{ score }}
  # Find all images in and under current directory using regular expression.
# Regex should start with .* because find displays full path.
find . -regextype awk -regex ".*(jpg|jpeg|png)$"
        
{{ score }}
  # count the number of files (-type f will ignore directories) by finding them, then piping them to wc (word count) using -l (lines only)
find DIR_NAME -type f | wc -l
        
{{ score }}
  # search for file entries only in current director (non-recursive)
find -type f -maxdepth 1

# finding directories in current folder, non-recursively
find -type d -maxdepth 1
        
{{ score }}
  # Lists all the files/folders the size of which is 100M or more
find -size +100M
        
{{ score }}
  # buscar ficheros binarios no usados en los últimos 100 días
find /usr/bin -type f -atime +100

# buscar ficheros creados o cambiados dentro de los últimos 10 días.
find /usr/bin -type f -mtime -10
        
{{ score }}
  # Find all images in and under current directory using regular expression.
# Regex should start with .* because find displays full path.
find . -regextype sed -regex ".*[jpg|jpeg|png]"