Unix Reference

find (find a file in a directory system)

Video

If you need to find a file in a particular directory, you can use the find command, which has a somewhat strange syntax:

$ pwd
/afs/.ir/users/c/g/cgregg/cs107/assignments
$ find . -name "hello.c"
./assign0/hello.c
./assign1/hello.c
$

The first argument (. above) is the directory you want to search (i.e., the current directory in the above search). This can be any directory:

$ find assign1 -name "hello.c"
assign1/hello.c
$

The second argument, -name means, "search for the name", and the final argument ("hello.c"), which is normally in quotes, gives the name to search for. find uses a slightly different wildcard than grep, so you can search for patterns like this (to search for all .c files):

``` $ find . -name "*.c" ./assign0/hello.c ./assign1/folder1/myProgram.c ./assign1/hello.c ./assign3/loop.c $

The find command has a vast number of options, so you would be wise to look online or use the man page for the command.

Back to contents