Find command examples in Linux

Find all files with a specific filename

find / -name filename

Find all files with a specific filename in the current location

find . -name filename

Find all files with a specific filename in a specific path

find /path -name filename

Find all files whose filename contains a specific word

find / -name 'word*'

Find all files whose filename has a specific extension

find / -name '*.ext'

Find only the first file with a specific filename

find / - name filename -type f -print -quit

Find all files whose content contains a specific word

find /path -type f -exec grep -H 'word' {} \;
find /path -type f | xargs grep 'word'

Find all files whose content contains a specific string

find /path -type f -exec grep -H 'specific string' {} \;
find /path -type f | xargs grep 'specific string'

Find all directories or folders with a specific name

find / -type -d -name 'dirname'

Find the files with a specific size

find /path -size 10M

Find all files within a specific size range

find /path -size +10M -size -100M

Find all files and folders by listing the permissions, users and groups.

find /path -exec stat -c '%a %U %G %n' {} \;

Find all files and folders that has a specific permission and list them

find /path -perm 755 -exec stat -c '%a%n' {} \;

Find all files and folders that belongs to a specific user

find /path -user username -exec stat -c '%U  %n' {} \;

Find all empty files and folders

find /path -type f -empty
find /path -type d -empty

Find all files that belong to a particular user

find /path -user username -name "file.txt"

Find the files that are modified, created and accessed within a specific time

find /path -mtime 10
find /path -ctime 10
find /path -atime 10

mtime, ctime and atime are used for specifying the time in days. Use mmin, cmin and amin for specifying the time in minutes.

Use find /path -mtime +10 -mtime -100 for specifying a range

Asha

Asha

I am a self mentored web enthusiast who likes to inspect element everything I see on the web.