10 ways to use the UNIX find command
Finding a single file Link to heading
$ find /etc/ -name httpd.conf
Finding directories only Link to heading
$ find . –type d –name code
Listing zero sized files and directories Link to heading
$ find ~ -empty -exec ls {} \;
Finding all the files of a given user Link to heading
$ find . -user www
Finding files within a size range Link to heading
The following command finds files that are bigger than 100 Mbytes:
$ find . –size +100M
Finding files using date parameters Link to heading
The following command finds files that are older than 15 days:
$ find . –mtime +15
The following command files all the files named Makefile
and loads all of them in the vi editor:
Link to heading
$ vi `find . -name Makefile`
Defining the directory depth of the search Link to heading
$ find . -maxdepth 3
The following command finds the files that end in either .m
or .c
:
Link to heading
The find
command also supports logical expressions
$ find . \( -name "*.c" -o -name "*.m" \)
The following command finds all the files in the current folder and its subfolders that are owned neither by user mtsouk
nor by user www
:
Link to heading
$ find . ! \( -user www -o -user mtsouk \) -exec ls –l {} \;