Indicates that a file (folder) is found under a path.
Entering a single
findwill display all files and folders in the current directory.
Search in the specified directory
Look in the
. /app/directory to find files.
Specify the type of file to find as a directory or file
-type dto find only directories,
dis short for directory and finds all directories in the current directory.
-type fto find only files,
fis short for file. Find all files in the current directory.
Specify file (folder) name search
-name <name>to find files (folders) with the name
<name>. Find the file with the name
file1.txtin the current directory and subdirectories.
Names support wildcards, but must be included in quotation marks.
Search by path
-pathmeans find by path.
Combined lookup: AND and OR operators
-ormeans or, the following command finds the file (folder) with the name
file1.txtor the name
-andmeans with (and), the following command looks for a folder whose name satisfies
file1*and is a folder.
Suppose you want to find files of type
jsand ignore the suffix case, you can do so.
$ find . -name "*.js" -or -name "*.JS" -or -name "*.Js" -or -name "*.jS"
Similarly you can simply add an
nameto indicate that case is ignored.
$ find .-iname "*.js"
All of the previously mentioned options support prefixing
ito indicate case-insensitive.
A more complex operation can be added, using
NOTto mean not (no). Find files (folders) with names
*.htmlbut with paths other than
Delete the results of the search
You can use
-deleteto delete the results of a search, for example, to delete all html files in the current repository.
$ find . -name "*.html" -type f -delete
Note that using this option to delete folders does not delete non-empty folders. If you want to delete a folder, for example I want to delete all
node_modulesin the directory (I often have this need under large front-end projects), you can do so.
$ find . -name node_modules -type d | xargs rm -rf