find
find linux command cheatsheet by Thamizhiniyan C S
Introduction
The find command is used to search for files in a directory hierarchy.
Syntax
find [-H] [-L] [-P] [-D debugopts] [-Olevel] [starting-point...] [expression]
Important Flags
-H
Follow symbolic links on command line only.
-L
Follow all symbolic links.
-P
Never follow symbolic links.
-D
Process debugging option.
-name
Matches files/directories by name.
-type
Matches files by type.
-perm
Matches files by permission.
-user
Matches files by owner.
-mtime
Matches files by modification time.
-atime
Matches files by access time.
-cmin
Matches files by changed minutes ago.
-amin
Matches files by accessed minutes ago.
-size
Matches files by size.
-writable
Matches files that are writable.
Examples
man find
Read the manual for the find command
find . -name flag1.txt
find the file named “flag1.txt” in the current directory
find /home -name flag1.txt
find the file names “flag1.txt” in the /home directory
find / -type d -name config
find the directory named config under “/”
find / -type f -perm 0777
find files with the 777 permissions (files readable, writable, and executable by all users)
find / -perm a=x
find executable files
find /home -user frank
find all files for user “frank” under “/home”
find / -mtime 10
find files that were modified in the last 10 days
find / -atime 10
find files that were accessed in the last 10 day
find / -cmin -60
find files changed within the last hour (60 minutes)
find / -amin -60
find files accesses within the last hour (60 minutes)
find / -size 50M
find files with a 50 MB size
find / -size +100M
find files that are larger than 100 MB
find / -size +100M -type f 2>/dev/null
redirect errors to “/dev/null” and have a cleaner output
find / -writable -type d 2>/dev/null
Find world-writeable folders
find / -perm -222 -type d 2>/dev/null
Find world-writeable folders
find / -perm -o w -type d 2>/dev/null
Find world-writeable folders
find / -perm -o x -type d 2>/dev/null
Find world-executable folders
find / -name perl*
Find files/directories named "gcc*"
find / -name python*
Find files with setuid, suppress errors
find / -name gcc*
Find setuid files, suppress errors
find / -perm -u=s -type f 2>/dev/null
Find files with the SUID bit
find / -perm -4000 2>/dev/null
Find files with the SUID bit
find [directory path] -type f -newerat [start date range] ! -newerat [end date range]
Find files based on date accessed
find [directory path] -type f -newermt [start date range] ! -newermt [end date range]
Find files based on date modified
find [directory path] -type f -newermt '[date and time]'
Find files modified after a specific date
find [directory path] -type f -group [group name]
Find files based on group name
find [directory] -type l ! -exec test -e {} \; -print
To perform the search and locate the links that do not work (Find Broken Symbolic Links)
Last updated
Was this helpful?