Locating Files with locate and find Flashcards

1
Q

The locate command uses a database to…?

A

Quickly locate files on the system by filename.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

The find command performs a…?

A

real time, recursive search of the filesystem.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

The find command can search for files based on…?

A

inode information.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

The find command can perform…?

A

arbitrary commands on files.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

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…?

A

locate and find.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

The command locate prints the names of…?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

The command find can find files by name but can also search for…?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

The locate command quickly reports all files on the disk whose filename contains…?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

The locate command also supports…?

A

“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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

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…?

A

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.)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

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

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Usually, however, the find command is given criteria to…?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

While superficially similar to the locate command, find functions by performing a search in…?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Search Criteria for the find command:
Switch: -empty
Specification: ???

A

The file is a directory or regular file, and is empty.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Search Criteria for the find command:
Switch: -group [gname]
Specification: ???

A

The file is group owned by gnname.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Search Criteria for the find command:
Switch: -inum n
Specification: ???

A

The file has an inode number n.

17
Q

Search Criteria for the find command:
Switch: -links n
Specification: ???

A

The file has n links.

18
Q

Search Criteria for the find command:
Switch: -mmin n
Specification: ???

A

The file was last modified n minutes ago.

19
Q

Search Criteria for the find command:
Switch: -mtime n
Specification: ???

A

The file was last modified n days ago.

20
Q

Search Criteria for the find command:
Switch: -name [pattern]
Specification: ???

A

The file’s name matches the file glob pattern.

21
Q

Search Criteria for the find command:
Switch: -newer [filename]
Specification: ???

A

The file was modified more recently than filename.

22
Q

Search Criteria for the find command:
Switch: -perm [mode]
Specification: ???

A

The file’s permissions are exactly mode.

23
Q

Search Criteria for the find command:
Switch: -perm -mode
Specification: ???

A

All of the permission bits mode are set for the file.

24
Q

Search Criteria for the find command:
Switch: -perm +mode
Specification: ???

A

Any of the permission bits mode are set for the file.

25
Q

Search Criteria for the find command:
Switch: -perm +mode
Specification: ???

A

Any of the permission bits mode are set for the file.

26
Q

Search Criteria for the find command:
Switch: -size n
Specification: ???

A

The file has a size of n.

27
Q

Search Criteria for the find command:
Switch: -type c
Specification: ???

A

The file is of type c, where c is “f” (regular file), “d” (directory), or “l” (symbolic link). See the man page for more details.

28
Q

Search Criteria for the find command:
Switch: -user uname
Specification: ???

A

File is owned by the user uname.

29
Q

You can also specify what you would like done to files that meet the specified criteria. By default, if no criteria is specified, the file name is…?

A

printed to standard out, one file per line.

30
Q

Action Specifications for the find Command:
Switch: -exec [command];
Action: ????

A

Execute command on matching files. Use {} to indicate where filename should be substituted.

31
Q

Action Specifications for the find Command:
Switch: -ok [command];
Action: ????

A

Like -exec, but prompt for each file.

32
Q

Action Specifications for the find Command:
Switch: -ls
Action: ????

A

Print file in ls -dils format.

33
Q

The -exec mechanism is powerful: rather than printing the names of matching files…?

A

arbitrary commands can be run.

The -exec mechanism is awkward, because the syntax for specifying the command to run is tricky. The command should be written after the -exec switch, using a literal {} as a placeholder for the file name. The command should be terminated with a literal ;, but as will be seen a later Workbook, the ; has special significance to the shell, and so must be “escaped” by prepending a .