0
0
Linux CLIscripting~10 mins

File globbing (wildcards *, ?, []) in Linux CLI - Interactive Code Practice

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

Complete the code to list all files ending with '.txt' in the current directory.

Linux CLI
ls [1]
Drag options to blanks, or click blank then click option'
A*.txt
B?txt
C[a-z].txt
Dtxt*
Attempts:
3 left
💡 Hint
Common Mistakes
Using '?txt' matches only files with exactly one character before 'txt'.
Using 'txt*' matches files starting with 'txt', not ending.
Using '[a-z].txt' matches only files with a single lowercase letter before '.txt'.
2fill in blank
medium

Complete the code to list files with exactly three characters and ending with '.log'.

Linux CLI
ls [1]
Drag options to blanks, or click blank then click option'
A*.???
B?*.log
C???.log
D*.log
Attempts:
3 left
💡 Hint
Common Mistakes
Using '*.log' matches any number of characters, not exactly three.
Using '*.???' matches files with any name and three-character extension.
Using '?*.log' matches files with at least one character before '.log', not exactly three.
3fill in blank
hard

Fix the error in the code to list files starting with 'data' followed by any single character and ending with '.csv'.

Linux CLI
ls data[1].csv
Drag options to blanks, or click blank then click option'
A*
B?
C[]
D[?]
Attempts:
3 left
💡 Hint
Common Mistakes
Using '*' matches zero or more characters, not exactly one.
Using '[]' or '[?]' is incorrect syntax for matching a single character.
4fill in blank
hard

Fill both blanks to list files that start with 'log', followed by a digit between 1 and 3, and ending with '.txt'.

Linux CLI
ls log[1][2].txt
Drag options to blanks, or click blank then click option'
A[1-3]
B?
C*
D[a-z]
Attempts:
3 left
💡 Hint
Common Mistakes
Using '?' after '[1-3]' matches exactly one character, but we want any number.
Using '[a-z]' matches letters, not digits.
Using '*' alone does not restrict the digit.
5fill in blank
hard

Fill all three blanks to create a dictionary comprehension that maps filenames to their extensions for files with names starting with 'img' and extensions '.jpg' or '.png'.

Linux CLI
files = ['img1.jpg', 'img2.png', 'img3.gif']
result = { [1]: [2] for file in files if file.startswith('img') and file.endswith([3]) }
Drag options to blanks, or click blank then click option'
Afile
Bfile.split('.')[-1]
C('.jpg', '.png')
Dfile.split('.')
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'file.split('.')' returns a list, not the extension string.
Using a single string in endswith instead of a tuple misses multiple extensions.
Using wrong keys or values in the dictionary comprehension.