Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to read the entire file content using a single command.
Linux CLI
cat [1] Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using commands like 'read' or 'open' which are not valid in this context.
Forgetting to specify the filename.
✗ Incorrect
The 'cat' command followed by the filename reads and outputs the entire file content.
2fill in blank
mediumComplete the command to read the first 10 lines of a file.
Linux CLI
head -n [1] file.txt Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using numbers other than 10 when the question asks for first 10 lines.
Omitting the '-n' option.
✗ Incorrect
The option '-n 10' tells 'head' to show the first 10 lines of the file.
3fill in blank
hardFix the error in the command to read a file line by line in a shell script.
Linux CLI
while IFS= read -r [1]; do echo "$line"; done < file.txt
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a variable name different from the one echoed inside the loop.
Not specifying a variable after 'read -r'.
✗ Incorrect
The variable 'line' is used to store each line read from the file in the loop.
4fill in blank
hardFill in the blank to create a command that counts the number of lines in a file.
Linux CLI
cat file.txt | [1] -l Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using commands like 'head' or 'tail' which do not count lines.
Leaving the blank empty.
✗ Incorrect
The 'wc -l' command counts the number of lines in the piped input.
5fill in blank
hardFill all three blanks to create a dictionary comprehension that maps words to their lengths for words longer than 3 characters.
Linux CLI
lengths = { [1]: [2] for [3] in words if len([3]) > 3 } Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using inconsistent variable names.
Mapping keys to wrong values.
✗ Incorrect
The comprehension uses 'word' as the variable, maps 'word' to 'len(word)', and iterates over 'word' in words.