0
0
Linux CLIscripting~5 mins

touch (create empty files) in Linux CLI - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What does the touch command do in Linux?
The touch command creates an empty file if it does not exist or updates the file's last modified time if it does exist.
Click to reveal answer
beginner
How do you create multiple empty files at once using touch?
You list all the file names separated by spaces after touch. For example: touch file1.txt file2.txt file3.txt creates three empty files.
Click to reveal answer
beginner
What happens if you use touch on a file that already exists?
The file's last access and modification timestamps are updated to the current time, but the file content stays the same.
Click to reveal answer
intermediate
How can you use touch to create a file with a specific timestamp?
Use the -t option followed by the timestamp in the format [[CC]YY]MMDDhhmm[.ss]. For example: touch -t 202401011200 file.txt sets the file's timestamp to Jan 1, 2024, 12:00.
Click to reveal answer
beginner
Why might you use touch in scripting or automation?
You can create placeholder files, update timestamps to trigger other processes, or ensure files exist before running commands that need them.
Click to reveal answer
What does the command touch newfile.txt do if newfile.txt does not exist?
ARenames newfile.txt
BDeletes newfile.txt
CDisplays the contents of newfile.txt
DCreates an empty file named newfile.txt
If file.txt exists, what does touch file.txt do?
AUpdates the file's last modified time
BDeletes the file
CChanges file permissions
DCopies the file
How can you create three empty files named a.txt, b.txt, and c.txt in one command?
Arm a.txt b.txt c.txt
Btouch a.txt b.txt c.txt
Cmkdir a.txt b.txt c.txt
Dcat a.txt b.txt c.txt
Which option with touch lets you set a custom timestamp?
A-c
B-r
C-t
D-a
Why might a script use touch before running another command?
ATo create or update files needed by the command
BTo delete files
CTo change file ownership
DTo compress files
Explain how the touch command works and give two common uses.
Think about creating files and changing file times.
You got /4 concepts.
    Describe how to use touch to set a file's timestamp to a specific date and time.
    Look for the option that controls time.
    You got /3 concepts.