Command line tricks : find #shellkungfu

This is the first of a long line of posts to improve your shell kungfu. And this post’s about one of the mostly used command: find.

This post will show you the basic and advanced uses of the command.

Find basic use:

“Name of file” can contains jokers:

Find in /etc all files with “conf” extension

Find files only:

Find files named “nginx”

Find folders only:

Find folders named “nginx”

Find in multiple dirs:

Find everything ending with “.d” in /var, /etc and /usr

Case insensitive search:

Find everything beginning with a “d”, case insensitive.

Find with multiple criterias

Find cpp and h files

Find not matching criteria:

Find in /etc files that are not a shell script

Execute command for each result

Find tmp files in /etc and remove them.

Find tmp files in /etc and copies them in /destfolder

Find with matching permissions

Find files with 777 permissions

Find executable files

Find empty files

Find empty files

Find with matching size

Search for files between 100Mb and 1Gb

Limit search depth

Find php files in /var/www/mysite only, not its subfolders.

For more, see find man page