Using the Linux find command – Usage with examples

Pinterest LinkedIn Tumblr

The Linux find command is a built in powerful tool that can be used to locate and manage files and directories based on a wide range of search criteria.For example, we can find files by their name, extension, size, permissions, etc.

Common Find commands

Searching for a file by name

find . -name data.txt

Find files larger than 100mb in the current dir:

find . -xdev -type f -size +100M

Searching for a specific file in a directory

find ./data -name tests*

Find files by extension:

find . -name *.jpg

Find files or directories with certain names:

# find only files, we need to use the -f option:
find ./ -type f -name "results*"

# To find only directories, we need to use the -d option:
find ./ -type d -name "results*"

Find files in multiple directories

find ./src ./res -name app*.* -type f

Find files containing a certain text

find ./src -type f -exec grep -l -i "getall" {} ;

Find files by size
We can even find files by different sizes. Size options are:

  • c bytes
  • k kilobytes
  • M Megabytes
  • G Gigabytes
    find / -size 10M

Find and delete specific files

find . -type f -name "temp*" -exec rm {} ;

I am a Devops Engineer, but I would describe myself as a Tech Enthusiast who is a fan of Open Source, Linux, Automations, Cloud and Virtualization. I love learning and exploring new things so I blog in my free time about Devops related stuff, Linux, Automations and Open Source software. I can also code in Python and Golang.

Write A Comment