Linux: “find” command line examples


here are a few examples how powerful the UNIX find command is.

Search only for file in your home directory “~”
find ~ -type f
Possible parameters for time searches:

  • mmin = Modication time in minute
  • mtime = Modication time in days
  • cmin = Creation time in minute
  • ctime = Creation time in days
  • amin = Access time in minute
  • atime = Access time in days

Find files which are modifed more then 60 min ago, starting search from root folder.

find / -mmin +60 -type f
Find files which are modifed within the last 60 min starting search from root folder.
find / -mmin -60 -type f
And in combination, files older than 60 min but not older than 120min.
find / -mmin +60 -mmin -120 -type f
The same with days, older than 1 day but not older than 3 days
find / -mtime +1 -mtime -3 -type f
Search for all files in / and exclude /sys from search
find /  ! -path "/sys/*"
Search files and exclude /sys and /proc from search
find / -mmin -240 ! -path "/sys/*" ! -path "/proc/*"
Find a file in multiple directories
find /bin /usr/bin -name gcc*
Find all files greater 2MB in /var
find /var -size +2M
Find all files starting with s* and c* in /usr/bin. Combine the two -name parameters with the or -o operator
find /usr/bin -name s* -o -name c*
Recursive search only up to 2 directory hierarchy levels
find / -maxdepth 2
Recursive search for files with a minimum of 3 directory hierarchy levels
find / -mindepth 3
List all files where string “eth0” is found, starting search in folder /etc
find /etc -type f -exec grep -l eth0 {} \; 2> /dev/null
Search with regular expressions. Note: The expression must match the whole path! Find all files that ends with disk an has 1 or 2 leading characters or all files that start with mkfs
find /sbin -regextype posix-egrep -regex '(.*\/.{1,2}disk)|.*\/mkfs\..*'
Looking for files with excutive permissions in tmp folder
find /tmp/ -perm /u=x,g=x,o=x -type f

To be continued


Time limit is exhausted. Please reload CAPTCHA.

Original Theme by Schiy · Powered by WordPress