Find command in Linux with examples

  • Home
  • /
  • Find command in Linux with examples
Find command in Linux with examples

Find command in Linux with examples

Linux 15 Jul 2018

In this article we will go over find command in linux with examples.

Find files by file name in current directory

Command : find -name '*Data*'

post thumb

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

Command : find -iname '*DAta*'

post thumb
Find directory by name

Command : find -type d -iname "Data"

post thumb
Find files which was modified recently

Command : find -mtime 2

post thumb
Find all files with specific permission

Command : find -type f -perm 777

post thumb
Find all files which has a specific word

Command : find -iname '*DAta*' -print | xargs grep "FNU"

post thumb

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

post thumb
Find files in current sub directory only (maxdepth)

Command : find -maxdepth 1 -type f -iname '*DAta*'
Command : find -maxdepth 2 -type f -iname '*DAta*'

post thumb
Find all files greater than specific size

Command : find * -size +10k -exec ls -l {} \;

Note : k is KB and m is MB in size

post thumb

Command : find * -size +10k;

post thumb
Find empty files in current directory

Command : find -type f -empty

post thumb
Find and delete the files

Command : find -type f -empty -delete

post thumb
Find all files which was accessed in last n days

Command : find -atime 0

*** 0 is today, 1 is yesterday and so on
***ctime can be replaced with cmin to filter on minutes instead of days

post thumb
Find all files which was modified in last n days

Command : find -mtime 0

***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

post thumb
Find all files which was changed in last n days

Command : find -ctime 0 -type f

***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

post thumb
Share: