find Usage.
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
Use
-type dto find only directories,dis short for directory and finds all directories in the current directory.Use
-type fto find only files,fis short for file. Find all files in the current directory. -
Specify file (folder) name search
Use
-name <name>to find files (folders) with the name<name>. Find the file with the namefile1.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 namefile1.txtor the namefile2.txt.-andmeans with (and), the following command looks for a folder whose name satisfiesfile1*and is a folder. -
Ignore case
Suppose you want to find files of type
jsand ignore the suffix case, you can do so.1$ find . -name "*.js" -or -name "*.JS" -or -name "*.Js" -or -name "*.jS"Similarly you can simply add an
i–-inamebeforenameto indicate that case is ignored.1$ find .-iname "*.js"All of the previously mentioned options support prefixing
ito indicate case-insensitive. -
NOT operator
A more complex operation can be added, using
NOTto mean not (no). Find files (folders) with names*.jsand*.htmlbut with paths other than*programs*. -
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.1$ find . -name "*.html" -type f -deleteNote 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.1$ find . -name node_modules -type d | xargs rm -rf