Skip to main content

LPI E - locate set test

Linux Search Showdown: Conquer the Practice Exam Challenge!

Ready, [set], locate!

LPI E 2.2

Question 1:
Which utility program can be used to perform a search based on a previously constructed database of files and directories on a Linux system?


A) ls
B) find
C) locate
D) grep

/* --------------------- */

--------------------------

Answer 1 Below: 

--------------------------

/* --------------------- */

Explanation:
The locate utility program performs a search using a pre-built database of files and directories on a Linux system. It matches entries that contain a specified character string, providing a list of relevant results. The other options, ls, find, and grep, do not rely on a pre-built database for searching files and directories.

Answer 1: C) locate

Question 2:
How can you obtain a shorter and more relevant list of files and directories when using the locate command?


A) By using the -l option
B) By using the -r option
C) By using the -s option
D) By piping locate output to grep

/* --------------------- */

--------------------------

Answer 2 Below: 

--------------------------

/* --------------------- */

Explanation:
To obtain a shorter and more relevant list of files and directories with the locate command, you can pipe the output of locate to the grep command. This allows you to filter the results and print only the lines that contain one or more specified strings. The other options listed do not provide a mechanism for refining the output of the locate command.

Answer 2: D) By piping locate output to grep

Question 3:
Which utility program is responsible for creating the database used by the locate command on most Linux systems?

A) updatedb
B) ls
C) grep
D) find

/* --------------------- */

--------------------------

Answer 3 Below: 

--------------------------

/* --------------------- */

Explanation:
The utility program updatedb is responsible for creating the database used by the locate command on most Linux systems. This utility is typically run automatically once a day to update the database with any changes to the file system. Running updatedb as the root user allows you to update the database manually if needed. The other options listed do not have a direct role in creating the locate database.

Answer 3: A) updatedb

Question 4:
When should the updatedb command be run to update the locate database?

A) Once a week
B) Once a month
C) Once a day
D) Only when the system is restarted

/* --------------------- */

--------------------------

Answer 4 Below: 

--------------------------

/* --------------------- */

Explanation:
The updatedb command should be run once a day to update the locate database. This allows the database to reflect any changes made to the file system, ensuring accurate search results with the locate command. While some systems may automatically run updatedb once a day, you can manually run it as the root user at any time to update the database. The other options listed do not reflect the recommended frequency for updating the locate database.

Answer 4: C) Once a day

Question 5:
Which character is used to pipe the output of one command to another command in Linux?

A) >
B) <
C) |
D) /

/* --------------------- */

--------------------------

Answer 5 Below: 

--------------------------

/* --------------------- */

Explanation:
The character | (pipe symbol) is used to pipe the output of one command to another command in Linux. This allows the output of the first command to serve as the input for the second command. In the given example, the output of locate zip is piped to grep bin using | to filter the results further. The other options listed (>, <, /) have different purposes and are not used for piping output between commands.

Answer 5: C) |

Question 6:
Which wildcard character is used to match any single character in a filename when searching for files in Linux?

A) [set]
B) [!set]
C) ?
D) *

/* --------------------- */

--------------------------

Answer 6 Below: 

--------------------------

/* --------------------- */

Explanation: The ? wildcard character is used to match any single character in a filename when searching for files in Linux. For example, ls ba?.out will match filenames with two characters before .out where the first two characters are "ba." The other options, [set], [!set], and *, have different wildcard meanings and do not specifically match a single character.

Answer 6: C) ?

Question 7:
What is the purpose of the * wildcard character when searching for files in Linux?

A) It matches any single character.
B) It matches any string of characters.
C) It matches any character in a set of characters.
D) It matches any character not in a set of characters.

/* --------------------- */

--------------------------

Answer 7 Below: 

--------------------------

/* --------------------- */

Explanation:
The * wildcard character is used to match any string of characters in a filename when searching for files in Linux. For example, ls *.out will match filenames with any characters before the .out extension. The other options listed have different wildcard meanings and do not represent the purpose of * when searching for files.

Answer 7: B) It matches any string of characters.

Question 8:
If you want to match any occurrence of either 'a', 'd', or 'f' in a filename when searching for files in Linux, which wildcard syntax should you use?

A) [set]
B) [!set]
C) ?
D) *

/* --------------------- */

--------------------------

Answer 8 Below: 

--------------------------

/* --------------------- */

Explanation:
The [set] wildcard syntax is used to match any character in a set of characters when searching for files in Linux. For example, [adf] will match any occurrence of 'a', 'd', or 'f' in a filename. The other options listed have different wildcard meanings and do not represent the syntax for matching specific characters in a set.

Answer 8: A) [set]

Question 9:
Which wildcard syntax allows you to match any character not in a set of characters when searching for files in Linux?

A) [set]
B) [!set]
C) ?
D) *

/* --------------------- */

--------------------------

Answer 9 Below: 

--------------------------

/* --------------------- */

Explanation:
The [!set] wildcard syntax allows you to match any character not in a set of characters when searching for files in Linux. For example, [!adf] will match any character that is not 'a', 'd', or 'f' in a filename. The other options listed have different wildcard meanings and do not represent the syntax for matching characters not in a set.

Answer 9: B) [!set]

Question 10:
You want to search for files with a three-letter filename and an extension of .out, but you only remember that the first two letters are "ba." Which wildcard syntax should you use?

A) [set]
B) [!set]
C) ?
D) *

Explanation: To search for files with a three-letter filename and an extension of .out when you only remember that the first two letters are "ba," you should use the ? wildcard syntax. For example, ls ba?.out will match filenames with two characters before .out where the first two characters are "ba." The other options listed have different wildcard meanings and do not represent the syntax for matching unknown characters in a filename.

Answer 10: C) ?