Unix find… Pretty useful if you ‘find’ out how to use it!

Captured at: 2015-09-15 10:16:48 UTC


find and command
– is a very useful command. We can use it to search for files based on modification time, size, names etc. It can then be used to execute a command based upon its’ results by causing the execution of a builtin unix command such as rm etc.


find . -size 0 -exec rm {} \;

The command above, finds all files with zero size and deletes them.


find . -anewer FileX -exec mv {} DirY \;

And this one above, finds all file in the current directory which were modified after FileX and moves them to directory DirY.


find . -type f -print0 | xargs -0 ls -l | sort -k5,5rn >> DirList.txt \;

The command above lists all the files in the current directory in a sorted list (size-wise)

Yet another very useful command is command (yes, what did you think?). It is great to check if there is an executable command in your path – super useful for situations when you need to conditionally execute something in a bash script for example.

Heres how I have used it to check for Doxygen in my tutorial on using Setuptools with Boost Python:

Sample usage of command in testing if Doxygen exists


if command -v doxygen; then cd aSimpleExample && doxygen Doxyfile && cd ..; \
	else echo "Doxygen not found. Not making documentation."; fi