Find command in Linux with examples

Sunday, July 15, 2018

Find command in Linux with examples



Find files by file name in current directory (case sensitive)
Command : find -name '*Data*'


Note : To find files in different directory specify directory name after the find command.
*** Command : find \directoryName\ -name '*Data*'

Find files by file name in current directory (case insensitive)
Command : find -iname '*DAta*'


Find directory by name
Command : find -type d -iname "Data"


Find files which was modified recently
Command : find -mtime 2

Find all files with specific permission
Command : find -type f -perm 777

Find all files which has a specific word
Command : find -iname '*DAta*' -print | xargs grep "FNU"

Command : find -iname '*DAta*' -type f -exec grep "FNU" '{}'  \; -print

Find files in current sub directory only (maxdepth)
Command : find -maxdepth 1 -type f -iname '*DAta*'
Command : find -maxdepth 2 -type f -iname '*DAta*'

Find all files greater than specific size
Command : find * -size +10k -exec ls -l {} \;
Note : k is KB and m is MB in size
Command : find * -size +10k;

Find empty files in current directory
Command : find -type f -empty


Find and delete the files
Command : find -type f -empty -delete

Find all files which was accessed in last n days
Command : find -atime 0
***Note : 0 is today, 1 is yesterday and so on
***ctime can be replaced with cmin to filter on minutes instead of days

Find all files which was modified in last n days
Command : find -mtime 0
Note :
***0 is today, 1 is yesterday and so on
***Modified means property was changed and not the content
***mtime can be replaced with mmin to filter on minutes instead of days

Find all files which was changed in last n days
Command : find -ctime 0 -type f
Note :
***0 is today, 1 is yesterday and so on
***Modified means property was changed and not the content
***ctime can be replaced with cmin to filter on minutes instead of days

No comments

Post a Comment

Error 404

The page you were looking for, could not be found. You may have typed the address incorrectly or you may have used an outdated link.

Go to Homepage