Finding Files and Directories

The find and locate commands can be used to search files on your system. The find command can be used to find files and directories not only based on the name or partial name of a file or directory but also from the age of the file (the time lapsed since the creation time until now), the size of the file, the last accessed time and many others. The locate command is used to quickly locate files or directories on your system. This program works very quickly ecause it uses a database of filenames instead of searching your hard drives.

To search for files or directories, specify a search path and search pattern on the command line. For example:

find /usr -name *emacs -xdev

The example above will search the /usr directory for the emacs editoer and other and other files locates th emacs program and its manual page, the -xdev option tell the command to search only your local machine (if there's any remotely mounted file system, it will be searched as well without the -xdev option and this will take a long tame).

another example would be finding files in /usr/bin directory which are accessed witihin the last 30 days. To do this, use the -atime option of the find command like so:

find /usr/bin -type f -atime +30 -print

the -type in the example above specifies that we want to find files (as opposed to a directory, symlink, device and so on).

You can also use the locate command to search for files and directories. For example, to look for any icons of the emacs text editor, use the locate command like this:

locate *icon*emacs*

The locate command searces a database called locatedb. This database is created with the updatedb command. System managers generally use the cron daemon and an updatedb crontab entry to keep the locate locatedb updated and accurate.

0 comments:

top