RSS Feed Subscribe to RSS Feed

Find files in Unix

I frequently end up searching an entire directory for an elusive file and I can never remember the exact command structure, so posting here:

    find /dir/to/search -name "filename.ext" -print 2>/dev/null

And wildcards are allowed. e.g.

    find /dir/to/search -name "filename.*" -print 2>/dev/null

The command searches /dir/to/search AND all sub directories.

The ’2>/dev/null’ avoids those annoying “find: cannot read dir …: Permission denied” errors.


Also, if you want to search for files containing specific text, try

    find /dir/to/search -exec grep -il "txtToSearchFor" {} \;

The “-il” means ignore case and print only the names of files with matching lines (as opposed to the line contents).

 

See also:
http://en.wikipedia.org/wiki/Find
http://www.unix.com/unix-dummies-questions-answers/3152-find-files-containing-text.html

Tags:

Leave a Reply