Section 2.5. I Don t Remember Where That File Is


2.5. I Don't Remember Where That File Is

With the thousands of files available on a Linux computer, people need help finding files now and then. For geeks, the two basic tools are find and locate. For regular users, there are KDE and GNOME search tools that are frontends to the find and locate commands.

The first part of this annoyance is a review of these commands for geeks. The second part covers the KDE and GNOME tools that your users will demand on their workstations. The key difference between these tools is that by default, the GNOME Search for Files tool uses locate, and the KDE Find Files tool uses find. As you should already know as a Linux geek, while locate works more quickly, it is less reliable than find.

2.5.1. The find Command

The find command is rich and complex. While I cannot cover everything that you can do with find, this book would not be complete without a discussion of it. If you need more information, refer to a book such as Unix Power Tools by Shelley Powers et al. (O'Reilly). The basic format of the find command is as follows:

 find path operators 

When you run this command, the path is the directory in which find should start looking. In other words, if you set the path to /home/michael, find looks in that directory and its subdirectories. It does not move up the directory tree. With the right operators, you can specify limitations, such as the file owner.

With the following examples, I describe some of the ways you can use the find command. In current Linux distributions, results are automatically sent to the screen; on older distributions, or some versions of Unix, you may need to add the -print option.


find .

Lists all files and subdirectories in the current directory, recursively.


find Desktop

Displays all files in the directory named Desktop right under the current directory.


find /home -name Downloads

Shows the location of every file or directory with the name Downloads that is somewhere in the /home directory tree.


find . -perm 777

Finds the location of all files under the current directory with read, write, and execute permissions for all users.


find /etc -type l

Lists all files in the /etc directory tree that are links (l) to other files; other types include d for a directory or b for a block file, which is characteristic of some devices. For the full list, see the manpage for find.


find /tmp -user michael

Shows all files in the /tmp directory that belong to user michael; you can substitute a user ID number.


find /tmp -group users

Shows all files in the /tmp directory that belong to the group users; you can substitute a group ID number.


find / -size +20000

Displays all files on your system with more than 20,000 blocks; as each block is 512 bytes, this specifies all files larger than approximately 10 MB. If you don't have enough space on your system, this can help you find huge files that you may have forgotten, such as DVD ISOs.


find /home/michael -atime -1

Finds all files last accessed in the past day (within the past 24 hours).


find /home/michael -ctime -2

Finds all files last changed in the past two days (within the past 48 hours).


find . -mtime +30 -type f -exec rm {} \;

Finds and deletes all files modified more than 30 days ago.

Any combination of these options can be specified to narrow the search further. For instance, if you specify both the -user and -perm options, files must match both the user and the permissions in order to be displayed.

You can configure search terms with multiple words or wildcards, as long as they're in single or double quotes. For example, if you mounted a Microsoft partition on /mnt/dos, you could find the path to the My Documents directory with the following command:

 find /mnt/dos -name  "My Documents" 

You can configure wildcards in the search in quotes as well. Alternatively, you can "escape" the meaning of a wildcard. For example, if you need to find files whose names contain a quote mark, you might run a search command such as:

 find / -name  \"Documents 

2.5.2. The locate Command

The locate command works more quickly than find. It works from a database of files, normally updated as a daily cron job. It works as a grep-based compressed database; in other words, wildcards such as the asterisk are not required. Normally, the database is configured to exclude files and directories mounted from network and temporary drives. The database is not updated if your computer is not running when the cron job is scheduled. In other words, if you turn your computers off at night, you may want to reschedule daily cron jobs to make sure this database is up-to-date.

Each of our major distributions configures the locate command and associated databases slightly differently:


Red Hat/Fedora

Red Hat/Fedora distributions install by default a secure version of locate, known as slocate (now mlocate, as of Fedora Core 5). It's configured through the /etc/updatedb.conf file, where you can enable daily updates of the database, and exclude appropriate directories such as /tmp and network filesystems such as NFS.


SUSE

If you want to take advantage of the locate utility on SUSE Linux, you'll have to install the findutils-locate RPM. If you do, you can configure its operation in the /etc/sysconfig/locate configuration file, where you can enable daily updates of the database, and exclude unwanted directories such as /tmp and network filesystems such as NFS.


Debian

Debian includes the find and locate utilities in the findutils DEB package. In a fashion similar to Red Hat/Fedora, you can configure how the locate database is kept up-to-date in the /etc/updatedb.conf file. When you configure that file, you can exclude unwanted directories such as /tmp and network filesystems such as NFS.

2.5.3. GNOME File Search Tool

You certainly don't expect ordinary Linux users to manage with the find and locate commands. Even many Linux geeks have trouble remembering all the associated options. This is one area where GUI tools can help. For example, the GNOME Search for Files tool serves as a frontend to the find, locate, and grep commands, used together. You can open this tool with the gnome-search-tool command.

The default settings for the Search for Files tool use the database associated with the locate command. If the database hasn't been updated in eight days, the user will see a warning message. When properly configured, the database is updated nightly as a cron job, as described earlier in this annoyance.


This is a very straightforward tool, as shown in Figure 2-3. As you can see, I've activated the "Show more options" settings, which allow you to modify the search by date, size, ownership, links, and more.

Figure 2-3. The GNOME Search for Files tool


This tool is closely related to the grep command. For more information on grep, see the next annoyance. For instructions that can help your users, you might adapt the following steps (if necessary, include screenshots with every step to help your users visualize the process):

  1. To start searching for files, click Places Search for Files. This opens the Search for Files window. If youre running an older version of GNOME, such as that associated with Red Hat Enterprise Linux 4 (GNOME 2.8), click Actions Search for Files.

  2. By default, the Search for Files tool starts the search in your home directory. If you have permission, you may be able to look for files in other users' home directories. To do so, substitute /home in the "Look in folder" text box. If your administrator has configured downloads in the /tmp directory, you may want to search that as well in order to find files left around by your programs.

  3. Click Find once you're satisfied with the search parameters. If the search takes too long, you can click Stop during the process.

If you want to limit the search to files with specific characteristics, use the following steps:

  1. Start with the first three steps described previously.

  2. Click the "Show more options" button. You'll see two additional settings: "Contains the text" and "Available options."

    I'll describe what you can do with the first option in the next annoyance. You'll want to modify your instructions accordingly.

  3. Click the "Available options" drop-down menu.

    You'll see a number of options that can help you limit your file search. They include the options described in Table 2-3.

    Table 2-3. Search for Files available options

    Option

    Description

    Date modified less than

    Searches for relatively new files; specifies how many days (maximum) are allowed to have passed since the file was last modified.

    Date modified more than

    Searches for relatively old files; specifies how many days must have passed (at minimum) since the file was last modified.

    Size at least

    Searches for files of at least a certain size, in kilobytes.

    Size at most

    Searches for files of less than a certain size, in kilobytes.

    File is empty

    Limits the search to files with 0 kilobytes.

    Owned by user

    Limits the search to files owned by the user of your choice.

    Owned by group

    Limits the search to files owned by the group of your choice.

    Name does not contain

    Limits the search to files whose names do not contain a specified search term.

    Name matches regular expression

    Searches for files whose names match the specified regular expression; allows you to specify a second search term.

    Show hidden and backup files

    Adds hidden and backup files to the search.

    Follow symbolic links

    Searches outside the directory path via symbolic links (see your administrator if you're interested in an explanation).

    Include other filesystems

    Allows you to search on other filesystems, such as remote directories mounted via Samba.


    Select the option of your choice, and click Add. If appropriate, another text box will appear, where you can add information such as the user, file size, or age.

  4. Repeat step 3 as desired.

  5. Once you've specified your file search parameters, click Find. If the search takes too long, you can click Stop during the process.

You should customize these instructions for your users. For example, if your users are primarily accountants, you could set up a specific example on how they could search through spreadsheet files such as client1.xls through client199.xls with a specific filename pattern, such as client1*.xls.

2.5.4. KDE File Search Tool

KDE has a file search tool similar to GNOME's. While configured differently, it is still a frontend to the find and grep commands, used together. You can open this tool with the kfind command.

The KDE search tool is also straightforward. While it divides search settings into three different tabsName/Location, Contents, and Propertiesthe overall capabilities are almost identical to the GNOME Search for Files tool.

For more information on the workings of the grep command, see the next annoyance. For instructions that can help your users, you might adapt the following steps (if necessary, include screenshots with every step to help your users visualize the process):

  1. To start searching for files, click the K menu Find Files. This opens the Find Files window.

    Enter the name of the file that you're looking for in the Named text box. By default, you'll need the full name of the file or directory that you need.

    If you don't know the full name of the file/directory you need, activate the "Use files index" option. This points the Find Files tool at the locate database described earlier.

    If you see an error message saying that the database is too old, consult your administrator for help on updating it for your newest files.

  2. By default, the Find Files tool starts the search in your home directory. If you have permission, you may be able to look for files in other users' home directories. To do so, substitute /home in the "Look in" text box. If your administrator has configured downloads in the /tmp directory, you may want to search that as well.

  3. If you're satisfied with the search parameters, skip to step 6. If you want to limit the search to a specific file type, click the Contents tab.

  4. Under the Contents tab, click the "File type" drop-down menu. Select one of the available file types, as described in Table 2-4.

    Table 2-4. Find Files Contents tab file-type options

    Option

    Description

    All Files and Folders

    Searches through and returns all matching entries in files and folders.

    Files

    Limits the search to files, not folders (directories).

    Folders

    Limits the search to folders.

    Symbolic Links

    Limits the search to files that are linked to others (see your administrator if you're interested in an explanation).

    Special Files

    Searches for nonstandard files, such as devices; this should not concern regular users.

    Executable Files

    Limits the search to files that you can run as programs.

    SUID Executable Files

    Limits the search to special files (normally owned by the administrative user) that you can run as programs.

    All Images

    Limits the search to all image files as defined by your administrator; may not include all image types.

    All Video

    Limits the search to all video files as defined by your administrator; may not include all video/movie file types.

    All Sounds

    Limits the search to all sound files as defined by your administrator; may not include all categories of sound files.

    Additional settings

    Allows you to select from a wide variety of file formats.


    If you want to limit the search to a specific file creation time, size, or owner, click the Properties tab.

    You can specify a file creation/modification date range, file size minimum or maximum, and the user or group that owns the file.

  5. Click Find once you're satisfied with the search parameters. If the search takes too long, you can click Stop during the process.

You should customize these instructions for your users. For example, if your users are primarily design engineers who use a computer-aided design (CAD) system, you could set up a specific example on how they could search for CAD drawing files with a specific filename pattern, such as project1*.cad.



Linux Annoyances for Geeks
Linux Annoyances for Geeks: Getting the Most Flexible System in the World Just the Way You Want It
ISBN: 0596008015
EAN: 2147483647
Year: 2004
Pages: 144
Authors: Michael Jang

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net