Find a File or Directory
Posted:
Saturday, February 18th, 2012Last modified:
Tuesday, March 31st, 2015Overview
Using the find command to locate files and directories from the command line.
# Find the directory named 'dirname' find ./ -name 'dirname' -type d # Find the file name 'filename' find ./ -name 'filename' -type f # Recursively find files and directories matching 'grepexpr*' find ./ -name 'grepexpr*'
Examples
File structure used in examples:
example/ frugle/ fruit_on_sale.txt sweater_sale.txt fruit/ fruit.txt fruit_intro.txt
Find all files and directories in 'example' which begin with 'fru':
find example/ -name 'fru*' example/fruit_intro.txt example/fruit example/fruit/fruit.txt example/frugle example/frugle/fruit_on_sale.txt
Find only directories beginning with 'fru':
find example/ -name 'fru*' -type d example/fruit example/frugle
Now we find only files beginning with 'fru':
find example/ -name 'fru*' -type f example/fruit_intro.txt example/fruit/fruit.txt example/frugle/fruit_on_sale.txt
Available Wiki Topics
The operator of this site makes no claims, promises, or guarantees of the accuracy, completeness, originality, uniqueness, or even general adequacy of the contents herein and expressly disclaims liability for errors and omissions in the contents of this website.