- Sections
- Misc.
Finding Files
Here is a really fast way to find files in Linux
Software Packages Required
Finding files from within Linux can be a challenge. The 'kfind' facility in KDE works by searching through folders looking for a match in filenames for the search string. This can be a very slow and laborious process.
Here we are going to learn about a much faster method using a command line utility called slocate. Slocate searches a database of every file on your computer and will return a list of all files which match a search string or a regular expression within a few seconds. Slocate is considerably faster than applications like kfind, but the disadvantage of slocate is it can only search for files added before the last database update. It is therefore important to update the slocate database regularly.
Installing slocate
Install slocate and anacron using the Mandriva Software Install GUI, or urpmi. After installation initialise the
database with updatedb in a root terminal. The purpose of installing the anacron package is to ensure
the database is kept up to date. Installing the slocate package puts a file into /etc/cron.weekly to run a weekly job to update the database.
However the default time to run this job is at 4am when most desktop computers will be switched off. The anacron package
ensures that any cron jobs which have been missed will be run when the computer is next switched on.
By default the index created will exclude certain folders and file system types. This is because there is no point indexing removable, or network media, or the system pseudo folders such as /proc. To see which folders and file systems are excluded look at /etc/updatedb.conf
Note that the /mnt folder is not indexed, and nor is vfat file system, so if you have a Windows
partition it will not be indexed unless you modify this file.
See 'man updatedb' for details, or enter #updatedb in the URL line of konqueror.
Using slocate
To use slocate simply enter slocate string_or_regex in a terminal. For example
$ slocate /usr/sbin/*drake /usr/sbin/adduserdrake /usr/sbin/diskdrake /usr/sbin/keyboarddrake /usr/sbin/logdrake /usr/sbin/mousedrake /usr/sbin/printerdrake /usr/sbin/rpmdrake /usr/sbin/rpmdrake-remove /usr/sbin/scannerdrake /usr/sbin/userdrake /usr/sbin/XFdrakewill find all files below /usr/sbin containing the string 'drake'
Searching for files within konqueror
There is a very nice plugin for konqueror called kio_locate available on any Mandriva contrib mirror. If you have a contrib source defined, then install it using the Mandriva Software Install GUI or urpmi. If you do not have a source for contrib defined, then go to Easy Urpmi to get one.
To use kio_locate open a konqueror window and enter locate:string_or_regex on the URL line.
Using regular expressions in your search strings can be very powerful. To learn about regular expressions enter
#regex in the URL line of konqueror or refer to the kio_locate page.
Sunday 11th March 2005

