preloader
blog-post

Find command in Linux with examples

Table of Contents

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

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

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

  • 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

  • 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

  • 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

Share this blog:
Comments

Related Articles