WEB TUTORIALS
PRACTICE EXAMPLES
HTML REFERENCES
CSS REFERENCES
PHP REFERENCES

How to Find a File by Name Using Command Line in Ubuntu

Topic: Ubuntu / LinuxPrev|Next

Answer: Use the find Command

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 f specify 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 -type d.


Related FAQ

Here are some more FAQ related to this topic:

Bootstrap UI Design Templates Property Marvels - A Leading Real Estate Portal for Premium Properties