Locating Files with locate and find Flashcards
The locate command uses a database to…?
Quickly locate files on the system by filename.
The find command performs a…?
real time, recursive search of the filesystem.
The find command can search for files based on…?
inode information.
The find command can perform…?
arbitrary commands on files.
It is common to find config files in /etc or executables in a bin directory, however, sometimes it is necessary to search the system for a specific file. Two of the common tools for this are…?
locate and find.
The command locate prints the names of…?
files and directories that match a supplied pattern.
It is the faster of the two commands because it relies on a database (updated daily by default) instead of searching real time. The downside of this is that it will not find files created today or it will find files that have been deleted since the last update of the database.
The command find can find files by name but can also search for…?
files by owner, group, type, modification date, and many other criteria. With its real time search through the directory tree, it is slower than locate but it is also more flexible.
The locate command quickly reports all files on the disk whose filename contains…?
the specified text.
The search relies on a database, which is updated nightly, so recently created files will probably not be reported. The database does remember file permissions, however, so you will only see files which you would normally have permissions to see.
The locate command also supports…?
“file globs”, or, more formally, pathname expansion, using the same *, ?, and […] expressions as the bash shell. For example, if you knew that there was a PNG image of a fish somewhere on the system, you might try the following locate command.
The find command is used to search the filesystem for files that meet a specified criteria. Almost any aspect of a file can be specified, such as…?
its name, its size, the last time it was modified, even its link count. (The only exception is the file’s content. For that, we need to wait for a command called grep, which complements find nicely.)
The find command’s syntax takes a little getting accustomed to, but once learned, is very usable. A find command essentially consists of three parts…?
A root directory (or directories), a search criteria, and an action.
The default directory is “.”, the default criteria is “every file”, and the default action is “print” (the filename), so running the find command without arguments will simply descend the current directory, printing every filename. If given a directory name as a single argument, the same would be done for that directory.
Usually, however, the find command is given criteria to…?
refine its search, in the form of (non standard) command line switches. For example, the -name command line switch is used to find files with a given name. As with locate, globs are supported, but should be quoted.
While superficially similar to the locate command, find functions by performing a search in…?
real time.
This can take a lot longer, but avoids the issue of an “out of sync” database. Note that if the proper ordering is not followed, find becomes quickly confused.
Search Criteria for the find command:
Switch: -empty
Specification: ???
The file is a directory or regular file, and is empty.
Search Criteria for the find command:
Switch: -group [gname]
Specification: ???
The file is group owned by gnname.