Using the find command in Linux with examples

This find command guide is a follow-up of my previous 90 Linux Commands frequently used by Linux Sysadmins article. Every week, or as time allows, I will publish articles on the ~ 90 commands geared toward Linux sysadmins and Linux power users. Let’s continue this series with the find command.

The find command is part of findutils which includes essential directory searching utilities for Linux and Unix-like operating systems. It allows for varied search criteria, formatted output, and custom commands to be run on the search results. I’ve also included some cheat sheets and other helpful reading at the end of this article.

Find command examples

Linux find - like a dog digging holes beach searching

To find directories matching a given name, in case-insensitive mode, use:

find path/ -type d -iname '*Dir_name*'

To find files by extension, use:

find path/ -name '*.ext'

To find files matching a path pattern, use:

find path/ -path '**/lib/**/*.ext'

To find files matching multiple patterns, use:

find path/ -name '*pattern1*' -or -name '*pattern2*'

To find files matching a given pattern, excluding a specific directory, use:

find path/ -name '*.py' -not -path '*/exclude_dir/*'

To find file larger than 500k use:

find path/ -size +500k

To find files sized between 500K and 10M, use:

find path/ -size +500k -size -10M

To find files modified in the last 7 days.

find path/ -name "*.txt" -mtime -60 -print

To find files modified in the last 7 days and delete them, use: find path/ -mtime -7 -delete

Linux find command – useful reading

Related commands

  • grep – a disk utility for Unix systems.
  • locate – also part of findutils.
  • whereis – Find the correct path to an executable file.

Conclusion

We’ve covered the find command used to search for files in a directory hierarchy. However, findutils also includes the locate command, which scans one or more databases of filenames and displays any matches, the updatedb command, which updates the file name database used by the locate command, and lastly the xargs command, which builds and executes command lines by gathering together arguments it reads on the standard input. Most often, these arguments are lists of file names generated by using find. Note, if no files to search are specified, the current directory (.) is used.

Tags: ,

Stop losing users to slow load times.

Blazing-fast, custom-configured NVMe Linux hosting.

Don't guess if your server is fast enough. Know it. Get a free performance audit of your current setup.

This blog is hosted by StackLinux, our parent company. 99.99% uptime.

Start Your Free Server Audit

You write the code. We'll manage the server.

Fully managed Linux hosting built for absolute speed.

Ditch the server maintenance headaches. Our experts custom-configure high-performance NVMe Linux servers specifically for your needs. Try us out. Your first month is entirely on us.

This blog is hosted by StackLinux, our parent company. 99.99% uptime.

Claim Your 30 Free Days

30 days of NVMe Linux hosting. $0 down.

Risk-free migration and a money-back guarantee.

We are so confident in our high-performance NVMe infrastructure that we'll audit your current server for free, migrate you without downtime, and give you 30 days to see the speed difference yourself.

This blog is hosted by StackLinux, our parent company. 99.99% uptime.

Deploy Free for 30 Days
Top ↑