Interview Q&A / Linux & Shell

BeginnerQuick answer1 min readUpdated 3 Oct 2026

What does the touch command do besides creating empty files?

SHORT ANSWER

touch updates a file's access and modification timestamps to now, and creates the file if it does not exist. You can also set a specific time with -t or -d, or copy another file's time with -r.

Explain it simply

Touch is like stamping a library card with today's date. If the card does not exist, a blank one is created. If it does, only the date changes and the contents stay as they were.

The creation of empty files is a side effect, not the main purpose. The real job is changing timestamps, which matters for tools that compare times, such as make, rsync, backup scripts and find -mtime.

Useful options: -d "2 days ago" sets a custom date, -t 202610011530 sets an exact time, -r other.txt copies the time from another file, and -c avoids creating a file that does not exist.

Example

bash
touch notes.txt                          # create or refresh
touch -d "2 days ago" old.log            # pretend it is old
find . -name "*.log" -mtime +1           # now old.log matches
# ./old.log

What to say in the interview

"touch sets the access and modification times to now, creating the file if missing. I use it to create placeholder files and to adjust timestamps when testing things like find -mtime or build tools that compare dates."

Common mistakes

  • Thinking touch changes file contents; it never does.

#linux#files#touch

Related questions

Practise more Linux & Shell questions

Test your recall with short answers, then return to the detailed explanations when you need context.

Open Linux & Shell quick answers →

Get new questions like this by email

One short email when something new and useful lands. No spam, unsubscribe in one tap.

By subscribing you agree to the Privacy Policy.