Linux for Developers Course
Linux for Developers
/
Beginner

locate

Definition

A command that searches for files by name. It is significantly faster than `find` because it queries a pre-built database instead of actively scanning the live hard drive.

Explain Like I'm New

Asking the librarian. Instead of walking through every aisle checking every book (which is what `find` does), `locate` just checks the library's pre-written index card catalog. It's instant.

Real World Example

You know you have a file called 'passwords.txt' somewhere on the computer. You type `locate passwords.txt`. It instantly prints the path.

Common Use Cases

  • •Rapidly finding lost files by name

Interview Questions

basic

  • Why is `locate` so much faster than the `find` command?

intermediate

  • You create a new file and immediately search for it using `locate`, but it says the file doesn't exist. Why?

Flash Cards

Question

Why faster?

Click to reveal answer
Answer

Because it doesn't search the hard drive. It searches a tiny text database that is usually built by the system once a day.

Question

Why can't it find new files?

Click to reveal answer
Answer

Because the index database hasn't been updated yet. To find a file you just created, you must run the `updatedb` command first, or just use the `find` command.