0
0
Linux CLIscripting~20 mins

touch (create empty files) in Linux CLI - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Touch Command Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate
1:30remaining
What is the output of this command sequence?
You run these commands in a Linux terminal:

touch file1.txt
ls -l file1.txt


What will the ls -l file1.txt command show about file1.txt?
Linux CLI
touch file1.txt
ls -l file1.txt
AShows an error: file1.txt does not exist
BShows file1.txt with size 100 bytes and current timestamp
CShows file1.txt with size 0 bytes and current timestamp
DShows file1.txt with size 0 bytes but timestamp from yesterday
Attempts:
2 left
💡 Hint
The touch command creates an empty file or updates the timestamp if it exists.
💻 Command Output
intermediate
1:30remaining
What happens when you run touch on an existing file?
Suppose example.txt already exists with some content.

You run:

touch example.txt

What changes after this command?
Linux CLI
touch example.txt
ANothing happens; file remains unchanged
BThe file content is erased and size becomes 0 bytes
CThe file is deleted
DThe file content stays the same but the modification timestamp updates to current time
Attempts:
2 left
💡 Hint
Touch updates timestamps without changing file content.
📝 Syntax
advanced
1:30remaining
Which touch command creates multiple empty files at once?
You want to create three empty files named a.txt, b.txt, and c.txt in one command.

Which command does this correctly?
Atouch a.txt b.txt c.txt
Btouch a.txt; b.txt; c.txt
Ctouch a.txt && touch b.txt && touch c.txt
Dtouch a.txt,b.txt,c.txt
Attempts:
2 left
💡 Hint
Touch accepts multiple filenames separated by spaces.
💻 Command Output
advanced
1:30remaining
What error occurs when using touch on a directory without permissions?
You try to run:

touch /root/secret.txt

But you are a normal user without root permissions.

What is the expected output?
Linux CLI
touch /root/secret.txt
Atouch: command not found
Btouch: cannot touch '/root/secret.txt': Permission denied
CFile /root/secret.txt created successfully
DNo output, command runs silently
Attempts:
2 left
💡 Hint
Normal users cannot write files in root-owned directories.
🚀 Application
expert
2:00remaining
How to create an empty file only if it does not exist using touch?
You want to create an empty file named log.txt only if it does not already exist.

Which command achieves this without changing the timestamp if the file exists?
Atouch -c log.txt
Btouch -a log.txt
Ctouch -t log.txt
Dtouch -n log.txt
Attempts:
2 left
💡 Hint
The -c option prevents creating a new file if it doesn't exist.