Find Command in Linux

Linux Logo

Find command in Linux

Examples

find /path/to/search -name *.txt

Find text files in a specific directory

find /path/to/search -name *.txt | grep -v .tmp

Find text files in a specific directory also exclude temp files

find . -name test -type d

In the current directory find directory named test

find . -name test -type f

In the current directory find file named test

find . -type f -name test -exec rm {} +

In the current directory find file(s) named test and remove it

find /Documents/ -type f -exec chmod 600 {} +

In /Documents find files and change permissions for each file to 600

find /Documents/ -type d -exec chmod 700 {} +

In /Documents find directories and change permissions for each file to 700 to they can be entered into

sudo find /var/log -type f -name *.log -exec truncate -s 0 {} +

As root find log files under /var/log and truncate them to 0

find . -name *.mp3

Find MP3 files in current directory