Linux updatedb Command
The updatedb
command is used to create or update the database file necessary for the slocate/locate
commands.
The execution process of the updatedb
command is lengthy because it traverses the entire system's directory tree and writes all file information into the slocate/locate
database file.
Note: slocate
itself has a database containing information about files and directories on the system.
Syntax
updatedb(options)
Parameters
--o<file> : Ignore the default database file and use the specified slocate database file;
--U<directory> : Update the slocate database for the specified directory;
--v : Display detailed execution process.
The following example checks for a non-existent file tutorialpro.txt:
# locate tutorialpro.txt # Search for tutorialpro.txt, no output indicates the file does not exist
# touch ./tutorialpro.txt # Add file tutorialpro.txt
# locate tutorialpro.txt # Search for tutorialpro.txt again, the file still does not exist
# updatedb # Update the locate.db database
# locate tutorialpro.txt # Search for tutorialpro.txt in the database again, the file is found
/root/tutorialpro/tutorialpro.txt
Using the -U option allows specifying the directory to update the slocate database for.
updatedb -U /root/tutorialpro/