How to Find a File by Name Using Command Line in Ubuntu
Topic: Ubuntu / LinuxPrev|Next
Answer: Use the
You can use the
find command to find or search for a file in a directory hierarchy.
find /path/to/directory -type f -name filename.ext
For example, to find the file named "sample.txt" within the
/var/www you can use:
find /var/www -type f -name sample.txt
To search this file within the whole file system you can simply use:
find / -type f -name sample.txt
To search this file within the current working directory you can use:
find . -type f -name sample.txt
The options have the following meanings:
-type: Search for files based on their type. The descriptor
fspecify a regular file.
-name: Sets the name of the file you are searching for.
Moreover, if you want to search for a directory use the option
Here are some more FAQ related to this topic:
- How to change current working directory in Ubuntu terminal
- How to open a text file in terminal in Ubuntu
- How to find and replace text within a file using command line in Ubuntu