Shell Scripting & Automation Flashcards
7 cards from real LCA practice questions. Tap to flip, then mark Knew It or Still Learning โ missed cards come back until you master them.
Read the first 7 Shell Scripting & Automation flashcards as text
Which cron field position specifies the day of the week?
Answer: Fifth field (0-7, where 0 and 7 = Sunday)
In a standard crontab, the five fields are minute, hour, day-of-month, month, day-of-week; the fifth field is day-of-week where both 0 and 7 represent Sunday.
What does `awk '{print $NF}' file` print?
Answer: The last field of each line
`NF` is the built-in awk variable for the number of fields, so `$NF` refers to the last field.
Which sed command deletes lines 3 through 7 from a file's output?
Answer: sed '3,7d' file
In sed, address ranges use a comma to separate start and end line numbers, followed by the command letter.
What is the effect of `chmod +x script.sh` on a script that has no execute bit set?
Answer: Adds execute permission for owner, group, and others
Using `+x` without specifying a user class adds execute permission to all three classes: user, group, and other.
Which bash substitution removes the longest matching suffix pattern from a variable?
Answer: ${var%%pattern}
`%%` removes the longest match of the pattern from the end (suffix), while `%` removes the shortest match.
How does `xargs -I {}` differ from plain `xargs` when constructing commands?
Answer: It places each argument at the {} placeholder position instead of appending at the end
`-I {}` defines a replace-string so each input item replaces `{}` wherever it appears in the command template.
What does `2>/dev/null` accomplish in a shell command?
Answer: Discards all error messages
Redirecting file descriptor 2 (stderr) to `/dev/null` silently discards all error output.