0
0
Linux CLIscripting~10 mins

Why reading files is constant in Linux CLI - Test Your Understanding

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete 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'
Aopen
Bread
Cfile.txt
Dwrite
Attempts:
3 left
💡 Hint
Common Mistakes
Using commands like 'read' or 'open' which are not valid in this context.
Forgetting to specify the filename.
2fill in blank
medium

Complete 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'
A15
B5
C20
D10
Attempts:
3 left
💡 Hint
Common Mistakes
Using numbers other than 10 when the question asks for first 10 lines.
Omitting the '-n' option.
3fill in blank
hard

Fix 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'
Aline
Bfile
Ctext
Dinput
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'.
4fill in blank
hard

Fill 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'
Awc
Bhead
Ctail
Dsort
Attempts:
3 left
💡 Hint
Common Mistakes
Using commands like 'head' or 'tail' which do not count lines.
Leaving the blank empty.
5fill in blank
hard

Fill 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'
Aword
Blen(word)
Ditem
Attempts:
3 left
💡 Hint
Common Mistakes
Using inconsistent variable names.
Mapping keys to wrong values.