locate

locate finds the locations of directories and files on Linux as well as other Unix-like OS.

$ locate hello.cpp

Useful Options / Examples

locate filename

This would list the absolute paths for all files with “filename” in the name.

$ locate hello.cpp
/home/user/Desktop/Folder/hello.cpp

Note: The locate command does not work for macOS unless you create a locate database. You can create one by running the following command:

$ sudo launchtl load -w /System/Library/LaunchDaemons/com.apple.locate.plist

Another alternative is to use the find command using the following syntax:

$ find . -name "hello.cpp"
/home/user/Desktop/Folder/hello.cpp