Locate Newly Created Files in Linux

This articles goes over the Linux locate command, how to see when the locate database was last updated, and how to update the database the locate command pulls from to make sure it is up to date. This applies to Cloud and Dedicated Linux environments. 

Using the locate command

  1. Login to your Linux server via SSH
  2. Run this command:
    1. locate file_name
  3. The results from step 2 will return any file paths containing the string file_name

Determining When the locate Database was Last Updated

  1. Login to your Linux server via SSH
  2. Run this command:
    1. locate mlocate.db | grep "/var/lib" | xargs ls -alh | awk {'print $6" "$7" "$8'}
  3. Here is an example:
    1. [root@12345-1 ~]# locate mlocate.db | grep "/var/lib" | xargs ls -alh | grep -v "No such" | awk {'print $6" "$7" "$8'}
      Apr 6 18:34

This means if you added a new file to the Linux server after that time, locate will not find it. The next section will go over how to update the locate database so it is up to date.

Updating the locate Database

  1. Login to your Linux server via SSH
  2. Run this command
    1. updatedb&
  3. Keep running this command until it says updatedb is done
    1. jobs
  4. Here is an example:
    1. root@12345-1 ~]# updatedb&
      [1] 19588
      [root@12345-1 ~]# jobs
      [1]+  Done                    updatedb

 

Once these steps are done, you can run the locate command for any new files you added to your Linux server. It should be able to find them now.

  • 0 Users Found This Useful
Was this answer helpful?

Related Articles

Installing htop

htop is an interactive process viewer for Linux, which is a powerful alternative to the...

Bind Multiple IP Addresses to a Single Network Interface Card (NIC)

This tutorial demonstrates how to bind multiple IP addresses to a single NICI'll be using LAN...

Clear Memory Cache on Linux Server

By default the Linux OS has a very efficient memory management process that should be freeing any...

Set the time on a Linux server

Log into the server via SSHAt the shell prompt run the following command:date MMDDHHmmYYYYFor...

Check your disk usage in Linux

A good way to check your disk usage for folders on your Linux server is via shell.Download...