← Back

The Most Frequently Used find Commands

How to find a file containing a substring:

$ find . -name '*idubbbz*'

Or if it is not certain about the register:

$ find . -iname '*idubbbz*'

Note: Same for -regex & -iregex flags, if regex.7 is preferred over glob.7.

No need to pipe the output of find to xargs when there is a built-in way to execute a program on a found file.

For example, to find files that take up more than one gigabyte of space:

$ find . -type f -size +1G -exec ls -lh {} \;

Or even if you need to delete found files:

$ find . -name 'thumbs.db' -delete

If you are trying to find a file inside a directory that is a symbolic link to a directory, it is often a good idea to use -L flag so that find doesn't omit it, which it does by default. Example:

# find /usr/hdp/current -name spark-class

Gives no result. However:

# find -L /usr/hdp/current -name spark-class

finds the sought for files:

/usr/hdp/current/spark2-client/bin/spark-class
/usr/hdp/current/spark-thriftserver/bin/spark-class
/usr/hdp/current/spark2-historyserver/bin/spark-class
/usr/hdp/current/spark2-thriftserver/bin/spark-class
/usr/hdp/current/spark-historyserver/bin/spark-class
/usr/hdp/current/spark-client/bin/spark-class