1.11 Locating and Searching Files Flashcards
What is the advantage of using the locate utility over the find utility? What are the disadvantages?
- Advantage: the locate utility is much faster because it searches through a pre-built index of all the files in the filesystem, whereas the find utility physically walks through each directory looking for the criteria you specify
- Disadvantages: (a)the index has to be built and/or updated with the latest information before the command can be used, (b)index creation can take a long time and consume a lot of system resources, (c)the locate command is not as versatile or flexible as the find command, (d)the locate command is not installed by default on most systems.
When would you use the which command to locate a file?
Use the which command to display the full path to a particular shell command or utilty. It is not use to locate other kinds of files.
Which utilities can you use to locate a file?
- find
- locate
- whereis
- which
Which utilities can you use to locate and get information about a command?
Use the whereis command to locate and get information about a command.
What does it mean when a command is hashed?
When a command is hashed, it is in the shell’s hash table, which means the command command has been used recently.
How can you discover the category of a command?
Use the type command to discover the category of a command - what kind of command you are dealing with.
What commands can you use to search for text within files?
Use the grep (or egrep or fgrep) command to search for text within files.
How do you configure the system to use the locate command?
- Install the package containing the locate utility - findutils-locate
- Generate the index, /var/log/locatedb, using the updatedb command
What does the find command do?
Searches through all files (based on the file system) by name, file size, time created, and other options.
What does the -name option of the find command do?
The -name option locates a file or directory by name in a specific path. When using this option, enclose string arguments in single quotes and use wildcards for partial names.
What does the -iname option of the find command do?
The -iname option locates a file or directory by name in a specific path, like the -name option, but matching is not case-sensitive.
What does the -user option of the find command do?
The -user option finds files owned by a specific user.
What does the -size option of the find command do?
The -size option finds files of a specific size. Use the following options:
Which argument modifiers can be used with the -size option of the find command?
- c specifies the file size in bytes
- k specifies the file size in kilobytes
- M specifies the file size in megabytes
What does the -mtime option of the find command do?
The -mtime option finds files last modified before or after a specified number of days ago.
What does the -type option of the find command do?
The -type option specifies whether to find files or directories. The f argument specifies files, and the d argument specifies directories.
What does the -maxdepth option of the find command do?
The -maxdepth option specifies how many directory levels down to search.
What does the -print0 option of the find command do?
The -print0 option finds filenames with spaces.
What does the -o parameter of the find command do?
The -o parameter specifies a logical OR between options when searching with multiple criteria.
What does specifying . as the directory argument of the find command do?
Specifying . as the directory argument causes find to search the current directory and all subdirectories.
What does the locate command do?
Search an index file for specific parameters.
What are the main features of the locate command?
- Much faster than find.
- Uses /var/log/locatedb as the index file for searches.
- Uses the updatedb command to update the file index. The configuration file for updatedb is /etc/updatedb.conf
- Searches from the root (/) directory if no path is specified.
- Finds all files that contain the specified string without using wildcards.
- Does not, by default, verify that the file exists if its file index is outdated.
- Does not display files created after the last time the file index was updated.
- Does not search for files by attribute.
Where is the index file used by the locate command to conduct searches?
The locate command uses /var/log/locatedb as the index file when conducting searches.
How do you update the index file used by the locate command after file system changes?
The updatedb command updates the index used by locate to conduct searches.