Find a file by name using command-line

I would like to determine the location of a file using command-line. I have tried:

find . -type f -name "postgis-2.0.0"

and

locate postgis-2.0.0

to no avail. What is the command to determine the file's directory, provided its name?


Try find ~/ -type f -name "postgis-2.0.0" instead.

Using . will only search the current directory. ~/ will search your entire home directory (likely where you downloaded it to). If you used wget as root, its possible it could be somewhere else so you could use / to search the whole filesystem.

Goodluck


I would try:

sudo find / -type d -name "postgis-2.0.0"

The . means search only in the current directory, it is best to search everything from root if you really don't know. Also, type -f means search for files, not folders. Adding sudo allows it to search in all folders/subfolders.

Your syntax for locate is correct, but you may have to run

sudo updatedb

first. For whatever reason, I never have good luck with locate though.

locate uses database of files and directories made by updatedb. So if you have downloaded a new file there is more chance that your updatedb has not updated the database of files and directories. You can use sudo updatedb before using locate utility program. updatedb generally runs once a day by itself on linux systems.