1.11 Locating and Searching Files Flashcards

2
Q

What is the advantage of using the locate utility over the find utility? What are the disadvantages?

A
  • 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.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

When would you use the which command to locate a file?

A

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.

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

Which utilities can you use to locate a file?

A
  • find
  • locate
  • whereis
  • which
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Which utilities can you use to locate and get information about a command?

A

Use the whereis command to locate and get information about a command.

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

What does it mean when a command is hashed?

A

When a command is hashed, it is in the shell’s hash table, which means the command command has been used recently.

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

How can you discover the category of a command?

A

Use the type command to discover the category of a command - what kind of command you are dealing with.

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

What commands can you use to search for text within files?

A

Use the grep (or egrep or fgrep) command to search for text within files.

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

How do you configure the system to use the locate command?

A
  1. Install the package containing the locate utility - findutils-locate
  2. Generate the index, /var/log/locatedb, using the updatedb command
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What does the find command do?

A

Searches through all files (based on the file system) by name, file size, time created, and other options.

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

What does the -name option of the find command do?

A

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.

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

What does the -iname option of the find command do?

A

The -iname option locates a file or directory by name in a specific path, like the -name option, but matching is not case-sensitive.

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

What does the -user option of the find command do?

A

The -user option finds files owned by a specific user.

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

What does the -size option of the find command do?

A

The -size option finds files of a specific size. Use the following options:

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

Which argument modifiers can be used with the -size option of the find command?

A
  • c specifies the file size in bytes
  • k specifies the file size in kilobytes
  • M specifies the file size in megabytes
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What does the -mtime option of the find command do?

A

The -mtime option finds files last modified before or after a specified number of days ago.

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

What does the -type option of the find command do?

A

The -type option specifies whether to find files or directories. The f argument specifies files, and the d argument specifies directories.

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

What does the -maxdepth option of the find command do?

A

The -maxdepth option specifies how many directory levels down to search.

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

What does the -print0 option of the find command do?

A

The -print0 option finds filenames with spaces.

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

What does the -o parameter of the find command do?

A

The -o parameter specifies a logical OR between options when searching with multiple criteria.

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

What does specifying . as the directory argument of the find command do?

A

Specifying . as the directory argument causes find to search the current directory and all subdirectories.

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

What does the locate command do?

A

Search an index file for specific parameters.

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

What are the main features of the locate command?

A
  • 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.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
24
Q

Where is the index file used by the locate command to conduct searches?

A

The locate command uses /var/log/locatedb as the index file when conducting searches.

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

How do you update the index file used by the locate command after file system changes?

A

The updatedb command updates the index used by locate to conduct searches.

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

How does the -coption modify the behavior of the locate command?

A

locate -c counts the number of entries rather than list them.

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

How does the -eoption modify the behavior of the locate command?

A

locate -e lists files only after verifying that they exist.

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

How does the -ioption modify the behavior of the locate command?

A

locate -i ignores case.

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

How does the -loption modify the behavior of the locate command?

A

locate -l limits the number of files listed.

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

How does the -boption modify the behavior of the locate command?

A

locate -b searches for the string in only file or directory base names.

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

What does the which command do?

A

Displays the path to a command and determines whether a package is installed.

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

What does the whereis command do?

A

Displays the path to the binary files, the manual pages, and the source code. With no options, whereis show all available data.

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

What does the command whereis -b do?

A

whereis -b lists the path to the binary file (similar to which).

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

What does the command whereis -m do?

A

whereis -m lists the path to the man page files.

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

What does the command whereis -s do?

A

whereis -s lists the location of the source code.

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

What does the command whereis -u do?

A

whereis -u lists entries that do not have source code, binary file, and man page locations.

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

What does the type command do?

A

type displays the category of the command. Possible categories include:

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

What are possible categories for the type command?

A
  • A built-in shell command
  • A command that the shell calls (external command)
  • An aliased command
  • A function
  • *Note**: If a called command has been used recently, the output says that the command is hashed, which means that it is in the shell’s hash table.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
39
Q

What does the comand find /user/home -name ‘*.txt’ do?

A

find /user/home -name ‘*.txt’ finds all plain text files in the /user/home directory.

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

What does the comand find / -name ‘*paper*‘ do?

A

find / -name ‘*paper*‘ looks through the entire directory for any folder or directory name with the term paper in it, such as termpaper.odt or wallpaper.jpg.

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

What does the comand find /user/home -size -300k do?

A

find /user/home -size -300k finds all files in the /user/home directory smaller than 300K.

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

What does the comand find /user/home -size +300k do?

A

find /user/home -size +300k finds all files in the /user/home directory larger than 300K.

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

What does the comand find /user/home -mtime -5 do?

A

find /user/home -mtime -5 finds all files in the /user/home directory modified within the last five days.

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

What does the comand find / -type f -name ‘*paper*‘ do?

A

find / -type f -name ‘*paper*‘ finds only files with the string paper in the name.

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

What does the comand find / -type d -name ‘*paper*‘ do?

A

find / -type d -name ‘*paper*‘ finds only directories with the string paper in the name.

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

What does the comand find -maxdepth 3 / -name ‘*.txt’ do?

A

find -maxdepth 3 / -name ‘*.txt’ finds text files three directory levels down from the root directory.

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

What does the comand find -print0 -name ‘*.txt’ do?

A

find -print0 -name ‘*.txt’ finds myreport.txt and my report.txt. Without the -print0 option, my report.txt is not listed.

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

What does the comand updatedb do?

A

updatedb updates the index file, /var/log/locatedb.

49
Q

What does the comand locate /user/home paper do?

A

locate /user/home paper locates all files with the string paper as any part of the file name or directory path under the /user/home directory.

50
Q

What does the comand locate lib do?

A

locate lib locates all files with the string lib anywhere in the file name or directory path.

51
Q

What does the comand locate -c lib do?

A

locate -c lib counts the number of files with the string lib.

52
Q

What does the comand locate -e .odt do?

A

locate -e .odt verifies that all .odt files listed in the file index actually exist before it lists them.

53
Q

What does the comand locate -i LibraryFines.csv do?

A

locate -i LibraryFines.csv finds the libraryfines.csv file regardless of case.

54
Q

What does the comand locate -l 25 lib do?

A

locate -l 25 lib lists only the first 25 files from the file index that contain the string lib.

55
Q

What does the comand locate -b lib do?

A

locate -b lib displays /var/lib and /user/home/libraryfines.csv but not /var/lib/usbutils/usb.ids.

56
Q

What does the comand which ls do?

A

which ls shows the path to the ls binary (executable) file.

57
Q

What does the comand which photorec do?

A

which photorec shows the path to the photorec binary file if photorec is installed. If the command does not display a path, then the photorec utility is not installed.

58
Q

What does the comand whereis -m -u * do?

A

whereis -m -u * lists all entries that have no man page location.

59
Q

What does the comand type cd do?

A

type cd displays cd is a shell built-in.

60
Q

What does the comand type more do?

A

type more displays the path to the binary file for more.

61
Q

What does the grep command do?

A

The grep command searches through file text for specific words or character patterns.

62
Q

What does the -A number option of the grep command do?

A

grep -A number prints a specified number of lines following the matching lines.

63
Q

What does the -a option of the grep command do?

A

grep -a searches binary (executable) files as though they were text files.

64
Q

What does the -B number option of the grep command do?

A

grep -B number prints a specified number of lines before the matching lines.

65
Q

What does the -C number option of the grep command do?

A

grep -C number prints a specified number of lines of context around the matching lines.

66
Q

What does the -c option of the grep command do?

A

grep -c shows the number of matches of the string for the file.

67
Q

What does the -E option of the grep command do?

A

grep -E uses regular expressions for the text pattern.

68
Q

What does the -e pattern option of the grep command do?

A

grep -e pattern specifies a literal pattern.

69
Q

What does the -f file_name option of the grep command do?

A

grep -f file_name searches for multiple strings using a file that lists the string patterns.

70
Q

What does the -F option of the grep command do?

A

grep -F uses a file as the source for the string patterns.

71
Q

What does the -i option of the grep command do?

A

grep -i ignores the case of the string.

72
Q

What does the -l option of the grep command do?

A

grep -l lists just the names of the files with a match.

73
Q

What does the -m number option of the grep command do?

A

grep -m number shows only a specified number of matches for a file.

74
Q

What does the -n option of the grep command do?

A

grep -n displays the line number of the lines containing the term.

75
Q

What does the -r option of the grep command do?

A

grep -r searches the directory and all sub-directories for files containing the term.

76
Q

What does the -v option of the grep command do?

A

grep -v displays non-matching lines.

77
Q

What does the –include=file_name option of the grep command do?

A

grep –include=file_name searches only in files with names that match a specified string.

78
Q

What does the –exclude=file_name option of the grep command do?

A

grep –exclude=file_name searches in files with names that do not match a specified string.

79
Q

What does the -w option of the grep command do?

A

grep -w searches for whole words only.

80
Q

What does the egrep command do?

A

The egrep command, like grep, searches through file text for specific words or character patterns, but allows regular expressions in the search strings. Uses the same options and syntax as grep and is identical to grep -E.

81
Q

What does the regular expression pattern ^ do?

A

^ matches terms that occur at the beginning of a line.

82
Q

What does the regular expression pattern $ do?

A

$ matches terms that occur at the end of a line.

83
Q

What does the regular expression pattern \< do?

A

\< matches words that begin with the term.

84
Q

What does the regular expression pattern \> do?

A

\> matches words that end with the term.

85
Q

What does the regular expression pattern [asdf] do?

A

[asdf] matches any one of the characters in the brackets.

86
Q

What does the regular expression pattern [0-9] do?

A

[0-9] matches any of the range of numbers 0-9.

87
Q

What does the regular expression pattern [^xyz] do?

A

[^xyz] omits any one of the letters in the list

88
Q

What does the regular expression pattern . do?

A

. matches any single character.

89
Q

What does the regular expression pattern [asdf]+ do?

A

[asdf]+ matches one or more of the characters in the list.

90
Q

What does the regular expression pattern * do?

A

* matches any number, or none of the preceding single character

91
Q

What does the regular expression pattern | do?

A

| matches either of the terms.

92
Q

What does the regular expression pattern *c* do?

A

**** displays the literal value of a character used for expressions.

93
Q

What does the regular expression pattern () do?

A

() groups expressions.

94
Q

What does the fgrep command do?

A

The fgrep command, like grep, searches through file text for specific words or character patterns, but searches only for fixed strings, not wildcards or regular expressions, and is much faster than grep. Uses the same options and syntax as grep and is identical to grep -F.

95
Q

What does the command grep -A 3 Midway ~/docs/WWII-report do?

A

grep -A 3 Midway ~/docs/WWII-report searches WWII-report for the pattern Midway and prints the line and the next three lines.

96
Q

What does the command grep -a var11 /bin do?

A

grep -a var11 /bin searches all files, including binary files, in the /bin directory for the pattern var11.

97
Q

What does the command grep -c 3 Midway ~/docs/WWII-report do?

A

grep -c 3 Midway ~/docs/WWII-report shows only the number of times the pattern Midway is found in the WWII-report file.

98
Q

What does the command grep -e ‘–count’ ~/docs/doc1 do?

A

grep -e ‘–count’ ~/docs/doc1 looks for the pattern –count in the doc1 file rather than interpreting it as an option.

99
Q

What does the command grep -l -r Midway ~/docs do?

A

grep -l -r Midway ~/docs shows the name of all files in the /home/user/docs directory that contain the term Midway.

100
Q

What does the command grep -m 2 battle ~/docs/WWII-report do?

A

grep -m 2 battle ~/docs/WWII-report shows only the first two times the term battle is found in the file.

101
Q

What does the command grep -n -i customVariable1 ~/java/program1.java do?

A

grep -n -i customVariable1 ~/java/program1.java shows the line numbers of lines that have the term customVariable1 in the program1.java file. This is case insensitive.

102
Q

What does the command grep -r battle ~/docs/ do?

A

grep -r battle ~/docs/ searches the directory and all sub-directories for the term battle.

103
Q

What does the command grep -w tank ~/docs/WWII-report do?

A

grep -w tank ~/docs/WWII-report searches only for the whole word tank in the file.

104
Q

What does the command egrep ^FAILURE ~/error_logs do?

A

egrep ^FAILURE ~/error_logs matches the term FAILURE when it is at the beginning of the line in error_logs.

105
Q

What does the command egrep tty7$ ~/.bash_history do?

A

egrep tty7$ ~/.bash_history matches the term tty7 when it is at the end of the line.

106
Q

What does the command **egrep ** do?

A

**egrep ** matches all words or strings that begin with are. This includes are, area, and arena.

107
Q

What does the command egrep \>are ~/myfile do?

A

egrep \>are ~/myfile matches all words or strings that end with are. This includes areI, hare, and aware.

108
Q

What does the command egrep watche[ds] ~/myfile do?

A

egrep watche[ds] ~/myfile matches either watched or watches.

109
Q

What does the command egrep exhibit[0-9] ~/myfile do?

A

egrep exhibit[0-9] ~/myfile matches exhibit1, exhibit3, or exhibit8.

110
Q

What does the command egrep [^Xx]mas ~/myfile do?

A

egrep [^Xx]mas ~/myfile matches Christmas but not xmas or Xmas.

111
Q

What does the command egrep .are ~/myfile do?

A

egrep .are ~/myfile matches hare and care, but not aware or are.

112
Q

What does the command egrep file[0-9]+ ~/myfile do?

A

egrep file[0-9]+ ~/myfile matches file0, file10, and file15636.

113
Q

What does the command egrep fil* ~/myfile do?

A

egrep fil* ~/myfile matches fil, filll, and fillllllllllllllll.

114
Q

What does the command egrep fil.* ~/myfile do?

A

egrep fil.* ~/myfile matches file, fill, file102, and filings.

115
Q

What does the command egrep men|women ~/myfile do?

A

egrep men|women ~/myfile matches men or women.

116
Q

What does the command egrep Hello\? ~/myfile do?

A

egrep Hello\? ~/myfile matches Hello?.

117
Q

What does the command fgrep Midway Nimitz ~/docs/myfile do?

A

fgrep Midway Nimitz ~/docs/myfile searches myfile for lines containing Midway or Nimitz.