MODULE 10- Working with text Flashcards

1
Q

Which type of files make up a large portion of a typical Linux file system and contain only unformatted text?

A

→ Text files, which include only raw text without formatting like that found in word processing documents.

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

Which command is not ideal for viewing large files because it dumps the entire content without a way to pause or resume?

A

→ The cat command, which displays everything at once with no built-in paging control.

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

Which command, short for “concatenate,” is used for creating, viewing, and combining text files?

A

→ The cat command, which can display, create, or concatenate the contents of text files.

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

Which shell feature allows users to send the output of commands to files or other commands instead of just displaying it in the terminal?

A

Output redirection

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

Which command is more advanced and is typically the default pager for tools like the man command?

A

→ The less command, which offers advanced paging capabilities and is often set as the default pager.

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

Which command, though older and less feature-rich, is always available on Linux systems when less is not?

A

→ The more command, a legacy pager present since the early days of UNIX.

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

Which command, despite being less capable, is guaranteed to exist on all Linux distributions?

A

→ The more command, known for its universal availability.

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

Which command is used to display the help screen while viewing a file with less?

A

→ The H key or Shift+H, which opens a help screen listing available movement commands.

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

Which key should you press to advance forward one window while using the less pager?

A

→ The Spacebar, which moves the view one full page forward.

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

Which key do you press after typing a search pattern to initiate the search?

A

→ The Enter key, which executes the search after entering a pattern with / or ?.

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

Which key combination moves the view backward by one window in both more and less?

A

→ The B key, which scrolls the content backward by one screenful.

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

Which key moves the cursor forward by a single line in both more and less?

A

→ The Enter key, which advances the view one line at a time.

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

Which key exits the pager interface in both the more and less commands?

A

→ The Q key, which quits the viewing session and returns to the shell.

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

Which type of expressions are used for matching text patterns in less searches?

A

→ Regular expressions, which define flexible matching rules for search queries.

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

Which key starts a backward search from your current position when using the less command?

A

→ The ? key, used to search in the reverse direction through the document.

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

Which key do you press in less to begin a forward search from your current position?

A

Which key do you press in less to begin a forward search from your current position?

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

Which key moves the cursor to the next matching result after a search in less?

A

→ The n key, which jumps to the next match in the current search direction.

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

Which key combination moves the cursor to the previous match during a search in less?

A

→ The Shift+N key, which reverses search direction and shows earlier matches.

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

Which command displays the first few lines of a file, defaulting to 10 lines?

A

→ The head command, used to view the beginning of a file or output.

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

Which command would you use to see the first 10 lines of /etc/sysctl.conf?

A

→ head /etc/sysctl.conf, which shows the default number of lines (10).

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

Which command shows the last few lines of a file, displaying 10 lines by default?

A

→ The tail command, which outputs the ending lines of a file or command result.

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

Which command would you use to see only the last 5 lines of /etc/sysctl.conf?

A

→ tail -5 /etc/sysctl.conf, using the numeric short option format.

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

Which option allows you to explicitly specify the number of lines to output in head or tail?

A

→ The -n option, followed by the number of lines.

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

Which command would output the first 3 lines of a file?

A

→ head -n 3 filename, using the long-form numeric option.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Which two formats are acceptable for outputting the last 3 lines with tail?
→ tail -3 filename or tail -n 3 filename.
18
Which command would you use to show all but the last 3 lines?
head -n -3 filename
18
Which command shows everything from line 25 onward in a file?
→ tail -n +25 filename, where the + tells tail to start from that line number.
19
Which command would number lines and then display content from line 25 onward in /etc/passwd?
→ nl /etc/passwd | tail -n +25, combining line numbering and tail starting from line 25.
20
Which command shows the last lines of a file and updates them in real time as the file grows?
→ tail -f filename, which follows file changes live.
21
Which option allows tail to monitor file changes continuously as new lines are added?
→ The -f option, useful for live monitoring like log file analysis.
22
What does tail -n +10 do?
→ Starts output from line 10 and prints all remaining lines to the end.
23
What does head -n -3 do in GNU head?
→ Outputs all lines except the last 3 from the file.
23
What does tail -n -3 do in both traditional and GNU systems?
→ Displays the last 3 lines of the file.
24
Which shell character allows the output of one command to be used as the input of another?
→ The pipe character |.
25
What command numbers the lines of its input, useful for tracking line positions in piped output?
→ The nl (number lines) command.
25
Which standard stream refers to normal command output and is labeled as channel #1?
→ Standard output (STDOUT)
26
Which standard stream handles error messages and is labeled as channel #2?
→ Standard error (STDERR)
26
Which standard stream refers to data entered by the user, typically from the keyboard?
→ Standard input (STDIN)
27
What symbol is used to redirect STDOUT to a file, overwriting any existing content?
>
28
What symbol is used to append output to an existing file rather than overwriting it?
>>
29
What happens when echo "Line 1" > file.txt is run?
→ STDOUT is redirected to file.txt, overwriting its contents.
30
Which file redirection method ensures that new content is added to the bottom of the file?
→ Appending using >>
31
What is the default stream used when no number is placed before >?
→ Standard output (STDOUT, stream #1)
31
Which channel number is associated with STDIN?
→ Channel 0
32
Which stream must be explicitly specified using 2>
→ Standard error (STDERR)
33
What redirection syntax is used to send STDERR to a file?
2> filename
34
Which command redirects both STDOUT and STDERR to a single file?
→ command &> filename
35
What does the &> operator mean in the context of redirection?
→ It means redirect both STDOUT (1>) and STDERR (2>) to the same file.
36
What does the command ls /fake /etc/ppp > example.txt 2> error.txt demonstrate?
saves STDOUT to example.txt and STDERR to error.txt simultaneously
37
Which redirection symbol is a shortcut that redirects both STDERR and STDOUT to the same file?
&>
37
What key combination do you use to stop a command like cat that waits for keyboard input from STDIN?
Ctrl+C
38
Which input stream can be redirected using the < character?
→ STDIN
39
Which command converts all lowercase letters to uppercase using STDIN from the keyboard?
→ tr 'a-z' 'A-Z'
40
Which command uses the < symbol to feed a file into tr for processing?
→ tr 'a-z' 'A-Z' < example.txt
41
How would you convert lowercase to uppercase in a file using INPUT redirection.
tr 'a-z' 'A-Z' < filename
42
Which command rearranges lines in files or input in alphabetical or numerical order?
→ The sort command rearranges lines of files or input in either dictionary (alphabetical) or numeric order.
42
Which option to the wc command displays only the number of words?
→ The -w option limits output to the word count only.
42
Which command displays the contents of the mypassword file on the terminal?
→ The cat mypasswd command outputs the contents of the mypassword file.
42
Which command creates a file named mypassword by extracting the first 5 lines of /etc/passwd?
→ head -5 /etc/passwd > mypasswd creates the mypassword file by redirecting the first 5 lines of /etc/passwd.
42
Which option to the sort command is used to ensure numbers are treated as numeric values during sorting?
→ The -n option instructs the sort command to perform a numeric sort rather than a dictionary sort.
42
Which command-line option defines the field delimiter for the sort command?
→ The -t option sets the delimiter used to divide fields, such as -t: for colon-separated data.
42
Which command alphabetically sorts the contents of the mypassword file?
→ sort mypasswd sorts the lines of the mypassword file in dictionary order.
42
Which command sorts the third field in descending numeric order using colon-delimited fields in the mypasswd file?
→ sort -t: -n -r -k3 mypasswd sorts the third field numerically in reverse order.
42
Which command sorts text by the third field numerically, using : as the delimiter in the mypasswd file?
sort -t: -n -k3 mypasswd
42
Which option to the sort command specifies which field to sort by?
→ The -k option is used to define the field number to sort by, such as -k3 for the third field.
42
Which option reverses the default sorting order of the sort command?
→ The -r option is used to perform a reverse sort.
42
Which sorting behavior is applied if no field or delimiter options are specified with the sort command?
→ A default alphabetical sort is applied, using whitespace as the field delimiter.
42
Which sort option would Numerically sort by field #1?
-k1n
43
Which command shows the number of lines, words, and bytes in one or more files, and prints a total if multiple files are specified?
→ The wc command displays line, word, and byte counts for each file, as well as the total if multiple files are used.
43
Which option to the wc command displays only the number of lines in a file or input?
→ The -l option limits the output to only the line count.
43
Which command can extract specific columns from a file or input, especially useful for delimited data?
→ The cut command extracts specific fields from files or standard input, especially delimited text.
43
Which command is often used on delimited database files and works with fields separated by a character like a colon or comma?
→ The cut command is used for field extraction from delimited files, commonly separated by characters like : or ,.
43
Which four columns are included in the default output of the wc command when multiple files are given?
The columns represent: number of lines, number of words, number of bytes, and the file name.
43
Which option to the wc command restricts output to the byte count only?
→ The -c option displays only the number of bytes.
43
Which command would you use to count how many files are in the /etc directory by using a pipe?
→ ls /etc/ | wc -l pipes the list of files into wc to count the number of lines, which equals the number of files.
43
Which option allows you to change the delimiter used by the cut command?
→ The -d option sets a custom delimiter for field separation.
43
Which option allows you to specify which fields to extract in the cut command?
→ The -f option is used to define the field numbers to extract.
43
Which symbols are used with the -f option to select multiple fields: one for ranges, the other for separate fields?
→ A hyphen - is used for field ranges, and a comma , is used to list specific fields.
43
Which command filters lines from a file or command output that match a specific pattern?
The grep command.
43
Which option enables the cut command to extract characters based on specific positions in each line?
→ The -c option selects columns based on character position, useful for fixed-width data.
43
Which grep pattern finds all lines in a file that end with the letter r?
r$
43
Which grep option Matches whole words only, ignoring partial word matches?
-w option
43
Which command extracts fields 1, 5 through 7 from a colon-delimited mypassword file?
→ cut -d: -f1,5-7 mypasswd extracts the username, full name, home directory, and shell fields.
43
Which grep option Makes the search case-insensitive, matching any capitalization?
-i option
43
Which grep option displays the number of matching lines instead of the lines themselves?
The -c option.
43
What does the --color option do in the grep command?
Highlights the matched pattern in red for visibility.
43
Which grep option Inverts the match, showing all lines that do not contain the pattern?
-v option
43
Which grep option Displays the original line numbers of matching lines?
-n option
44
Which regular expression character Matches any single character?
the . character
44
Which regex pattern matches any single character except the ones explicitly listed inside square brackets?
A negated character class like [^abc].
44
Which character anchors the regex match to the beginning of a line?
The caret (^) character when placed at the start of the pattern.
44
Which regex character matches any one of the listed characters, such as a, b, or c?
A character class written as [abc]
44
Which symbol in a regular expression matches zero or more repetitions of the character that comes before it?
The asterisk (*) character.
44
Which character restricts a regex pattern to only match text at the end of a line?
The dollar sign ($).
44
Which pattern would match any number between 0 and 9 in a text file?
[0-9]
44
Which grep command would you use to match only lines in /etc/passwd that start with the word root?
grep '^root' /etc/passwd
44
Which character is used to escape special regex characters like * when searching for their literal value?
Backslash \
44
Which pattern would match any string that starts with r, is followed by exactly two characters, and ends with f (e.g., “reef” or “roof”)?
r..f
44
Which regular expression would you use to match any non-digit character, excluding 0 through 9?
[^0-9]
44
Which pattern would you use with grep to find lines in a file that contain four or more characters, regardless of what they are?
'....'
44
Which pattern matches red, rod, reed, reeed, and rd?
r[oe]*d
44
Which symbol, when placed as the first character inside square brackets, inverts the match to mean “any character except the ones listed”?
The caret (^) inside [ ].
44
Which command-line tool lets you view ASCII values to help understand why ranges like [a-d] are valid and [d-a] are not?
The ascii command.
44
Which grep pattern matches red, reed, reeed, and rd using repetition of e?
re*d
44
Which grep pattern matches only lines in /etc/passwd that start with root?
^root
45
Which command is deprecated but was historically used to recognize extended regular expressions directly?
egrep
45
Which pattern matches all lines in red.txt with at least one e character in a row?
e+
45
Which option allows the grep command to interpret extended regular expressions?
-E
45
Which ERE operator matches the preceding character zero or one time, making it optional?
?
45
Which pattern matches either gray or grey using extended regex?
gray|grey
45
Which ERE pattern matches both color and colour?
colou?r
45
Which ERE operator matches one or more occurrences of the preceding character?
+
45
Which grep command can find both gray and grey in spelling.txt?
grep -E 'gray|grey' spelling.txt
45
Which symbol can also be used to redirect standard error and output to the same file?
2>&1