Q:

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

0

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

All Answers

need an explanation for this answer? contact us directly to get an explanation for this 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.

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now