YouTip LogoYouTip

Linux Comm Locate

# Linux locate Command [![Image 3: Linux Command Reference](#) Linux Command Reference](#) The Linux locate command is used to find documents that match specified criteria. It searches a database that stores document and directory names to find documents or directories that match the pattern. Generally, you only need to enter **locate your_file_name** to find a specific file. ### Syntax locate [pattern...] **Parameters:** * -b, --basename -- Match only the basename of path names * -c, --count -- Output only the count of matches * -d, --database DBPATH -- Use the database specified by DBPATH instead of the default database /var/lib/mlocate/mlocate.db * -e, --existing -- Only print entries for currently existing files * -1 -- If is 1, enable safe mode. In safe mode, users cannot see files they don't have permission to view. This slows down the process because locate must check file permissions on the actual filesystem. * -0, --null -- Output entries separated by NUL * -S, --statistics -- Do not search entries, print statistics about each database * -q -- Quiet mode, no error messages are displayed. * -P, --nofollow, -H -- Do not follow trailing symbolic links when checking file existence * -l, --limit, -n LIMIT -- Limit output (or count) to LIMIT entries * -n -- Display at most n outputs. * -m, --mmap -- Ignored for backward compatibility * -r, --regexp REGEXP -- Use basic regular expressions * --regex -- Use extended regular expressions * -q, --quiet -- Quiet mode, no error messages are displayed * -s, --stdio -- Ignored for backward compatibility * -o -- Specify the name of the database. * -h, --help -- Display help * -i, --ignore-case -- Ignore case distinctions * -V, --version -- Display version information ### Examples Find the passwd file, enter the following command: locate passwd Search for all files starting with sh in the etc directory: locate /etc/sh Case-insensitive search for all files starting with r in the current user's home directory: locate -i ~/r ### Additional Notes locate differs from find: find searches the hard drive, while locate only searches the database in /var/lib/slocate. locate is faster than find because it doesn't actually search the filesystem; it queries the database. The file database is typically located at /var/lib/slocate/slocate.db, so locate's results are not real-time but based on the database's update status. The database is usually maintained by the system, but you can manually update it with the command: updatedb By default, updatedb runs once a day. [![Image 4: Linux Command Reference](#) Linux Command Reference](#)
← Linux Comm LsattrLinux Comm Less β†’