locate – Internetblog.org.uk https://www.internetblog.org.uk Web hosting, Domain names, Dedicated servers Fri, 29 Jan 2016 11:05:52 +0000 en-US hourly 1 https://wordpress.org/?v=4.9.5 https://www.internetblog.org.uk/files/2016/01/cropped-favico-32x32.png locate – Internetblog.org.uk https://www.internetblog.org.uk 32 32 How to Display Files Modified Today https://www.internetblog.org.uk/post/1384/how-to-display-files-modified-today/ Wed, 02 Jun 2010 15:43:30 +0000 http://www.internetblog.org.uk/post/1384/how-to-display-files-modified-today/ File folder iconThere are many ways to search Linux files and directories using grep, find, or locate. All of them find files that match certain search parameters, usually words or characters. On a Linux server, you can also find any files that were modified within the current day. This is useful for finding security exploits and generally tracking website usage.

Using the find command, you can look for all files modified in a specific directory within the current day. To do so, enter the following string:

find -maxdepth 1 -type f -mtime -1

The output will look something like this:

./syslog
./lastlog
./user.log
./auth.log
./daemon.log
./mail.info
./syslog.1

To find only the directories created on the current day, simply change the “f” to a “d”:

find -maxdepth 1 -type d -mtime -1

Using this information can help you track down possible problems. Certain files like ones listed above are supposed to be modified daily, but if you find files that should not be modified, that can be a clue to help you fix whatever ails your server.

Image Source: Wikimedia Commons

]]>
Finding Linux files with "locate" https://www.internetblog.org.uk/post/1196/finding-linux-files-with-locate/ Mon, 12 Apr 2010 17:41:10 +0000 http://www.internetblog.org.uk/post/1196/finding-linux-files-with-locate/ Kid with magnifying glass
There are a few of ways to find files on a Linux server, but most of them involve actually searching through each file in the filesystem until the correct one is located. This can be time consuming and taxing on the server’s CPU load, especially if you have a lot of files.

Linux has two commands that make searching a little easier: locate and slocate. Unlike other find utilities, locate searches through a database that contains information about the filesystem, bringing up the search results almost instantaneously. The command to update the database is called “updatedb”, and many Linux distributions have the command run via cron every day.

The alternative version of locate, called slocate, is a security-enhanced version that only allows the user to find files he or she has the permission to access. While locate is a great tool for finding things on a server, it does have its issues. For one, you will only find files that were added or changed prior to the last updatedb execution. Furthermore, the very process of updating the database can be taxing on the server, even if it is only once a day. For the right situations, however, locate is a very useful Linux tool.

Photo Source: Flickr

]]>
How to Index and Find Files in Linux https://www.internetblog.org.uk/post/486/how-to-index-and-find-files-in-linux/ Mon, 14 Sep 2009 16:19:56 +0000 http://www.internetblog.org.uk/post/486/how-to-index-and-find-files-in-linux/ Source code
Question: I have a virtual private server (or dedicated server) with lots of files from numerous websites. How can I keep my files indexed and search for them whenever I need them?

Answer: There are two tools that make searching for files in Linux easy: locate and slocate. The only difference between the two is that slocate provides some extra security. This is useful if you have people on your server without full root permissions who will be performing the searches. Any files above their user level will be hidden.

If you try typing “locate filename” where “filename” is the name of an actual file, you should receive a list of all files with that name in it. If you do not, that means that your server is not setup to index the files. For that, you need another program called “updatedb”. This updates the index database with all of your files. Depending on the size of your drive, this can become an intense activity, so it is best to do it at a low usage time.

You can also schedule updatedb to run periodically using a cron job. Many Linux distributions have this enabled by default. If you need it, leave it on. If not, you might consider turning it off to save CPU and memory usage.

Photo Source: SXC

]]>