freebsd find

How to find files, programs, etc using freebsd

The locate command is good for finding files and directories. Enter something similar to:

locate someprogram | more

If that doesn’t work, perhaps try the whereis or find commands:

whereis someprogram | more

find / -name "someprogram*"

For variations on these commands, you can type:

man locate

man whereis

man find


To find the largest ten files on the disk:

find / -type f | xargs ls -s | sort -rn | awk '{size=$1/1024; printf("%dMb %s\n", size,$2);}' | head

To find the largest ten files in a directory:

for i in G M K; do du -ah | grep [0-9]$i | sort -nr -k 1; done | head -n 11

To search for a string recursively amongst a bunch of files/subdirectories install gnugrep (it replaces regular grep) and then run this (replace yoursearchstring):

find . -type f -print | xargs grep --mmap -l yoursearchstring

To replace all instances of a string in a directory with a backup of original file as .bak (subdirectories included):

perl -e "s/FIND/REPLACE/g;" -pi.bak $(find path/to/DIRECTORY -type f)

To replace all instances of a string in a directory without a backup of original file (subdirectories included):


perl -e "s/FIND/REPLACE/g;" -pi $(find path/to/DIRECTORY -type f)
(the last two were from

Leave a Reply

To create code blocks or other preformatted text, indent by four spaces:

    This will be displayed in a monospaced font. The first four 
    spaces will be stripped off, but all other whitespace
    will be preserved.
    Markdown is turned off in code blocks:
     [This is not a link](

To create not a block, but an inline code span, use backticks:

Here is some inline `code`.

For more help see

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>