Home »
Aptitude Questions and Answers »
Linux Aptitude Questions and Answers
Linux Regular Expressions Aptitude Questions and Answers
Linux Regular Expressions Aptitude Questions and Answers: This section contains aptitude questions and answers on Linux Regular Expressions.
Submitted by Nidhi, on May 21, 2020
This section contains Aptitude Questions and Answers on Linux Regular Expressions.
1) There are the following statements that are given below, which of them are correct about Regular expressions in the Linux operating system?
- The regular expressions are strings that are used for pattern matching in some Linux commands.
- The regular expressions are also known as a regex.
- The regular expressions use some characters that each has a different meaning.
- Regular expressions can only be used in the Linux commands.
Options:
- A and B
- C and D
- A, B, and C
- A, B, C, and D
Correct answer: 3
A, B, and C
Statements A, B, and C are correct about regular expressions.
2) Which of the following command uses regular expressions in the Linux operating system?
- grep
- sed
- rename
- bash
Options:
- A and B
- C and D
- A, B, and C
- A, B, C, and D
Correct answer: 4
A, B, C, and D
All given commands are used with regular expressions in the Linux operating system.
3) Which of the following types of regular expressions are used in the Linux operating system?
- Basic Regular Expression
- Extended Regular Expression
- Crond Regular Expression
- Perl Regular Expression
Options:
- A and B
- A, B, and D
- A, B, and C
- A, B, C, and D
Correct answer: 2
A, B, and D
Options A, B, and D are the correct types of regular expressions used in the Linux operating system.
4) Which of the following option is used for a basic regular expression in the grep command?
- -B
- -G
- -P
- -E
Correct answer: 2
-G
The option -G is used for a basic regular expression in the grep command.
5) Which of the following is used to match any set of characters from the specified file in the grep command?
- ()
- {}
- []
- ##
Correct answer: 3
[]
The [] is used to match any set of characters from the specified file in the grep command.
6) Which of the following symbols are used for a regular expression in the Linux?
- $
- ?
- _
- +
Options:
- A and B
- A, B, and D
- A, B, and C
- A, B, C, and D
Correct answer: 4
A, B, C, and D
All given symbols are used for regular expressions.
7) Which of the following symbol is used to match exactly one character?
- $
- ?
- _
- +
Correct answer: 2
?
The question mark (?) is used to match exactly one character.
8) Which of the following symbol is used to match preceding character N times or more than N times?
- (N)
- (N,)
- {N}
- {N,}
9) Which of the following symbol is used to represent the group of characters?
- /
- \
- +
- -
Correct answer: 2
\
The backward slash (\) is used to represent the group of characters.
10) Which of the following symbol is used to group regular expressions?
- []
- ()
- {}
- <>
Correct answer: 2
()
The parentheses are used to group regular expressions.
11) Which of the following symbol is used to match the empty string at the edge of a word?
- \<
- \>
- \B
- \b
Correct answer: 4
\b
The backslash b (\b) is used to match the empty string at the edge of a word.
12) Which of the following symbol is used to match the empty string if it is not at the edge of a word?
- \<
- \>
- \B
- \E
Correct answer: 4
\B
The backslash B (\B) is used to match the empty string if it is not at the edge of a word.
13) Which exact command is used, when we want to search words in the file that can be "ABC1", "ABC5", and "ABC8"?
- grep "ABC[0-9]" <filename>
- grep "ABC(0-9)" <filename>
- grep "ABC(0-9)" <filename>
- grep "ABC(0-9)" <filename>
Correct answer: 1
grep "ABC[0-9]" <filename>
The first option is correct.
14) Can we use regular expressions with awk command?
- Yes
- No
Correct answer: 1
Yes
Yes, we can use regular expressions with awk command.
15) Which of the following command is used to display only directories that exist in the current directory?
- ls –l | grep "^d"
- ls | grep "^d"
- ls –l | grep "#d"
- ls –l | grep "*d"
Correct answer: 1
ls –l | grep "^d"
The 1st command is correct.
16) Which of the following command is used to rename the file names that contain “text” with “txt” in the current directory?
- rename 'r/txt/text' *
- rename 'e/text/txt' *
- rename 's/txt/text' *
- rename 's/text/txt' *
Correct answer: 4
rename 's/text/txt' *
17) Which of the following command is used to replace the specific word, for example we want to replace inclusion by exclusion?
- echo inclusion | sed 's/in/ex'
- echo inclusion | sed 's/ex/in'
- echo inclusion | sed 'r/in/ex'
- echo inclusion | sed 'R/in/ex'
Correct answer: 1
echo inclusion | sed 's/in/ex'
The 1st command is correct to replace the specific word.
19) Which of the following symbol is used to match the empty string at the beginning of a word?
- \<
- \%
- \$
- \(
Correct answer: 1
\%
The \< is used to match the empty string at the beginning of a word.
20) Can we use regular expressions in VI editor?
- Yes
- No
Correct answer: 1
Yes
Yes, we can use regular expressions in VI editor.