December 2, 2026 - 21:51
Linux Lesson 07 — touch: Does It Create Files or Change Timestamps? Image
Linux Tutorials

Linux Lesson 07 — touch: Does It Create Files or Change Timestamps?

0 Comments

“Touch creates a file” is useful but incomplete. If the file does not exist, touch can create an empty one. If it already exists, its main job is updating timestamps. It does not erase existing notes.

Create a file in the practice area

Use the netopsiyon-dersleri directory from lesson six:

BASH
cd "$HOME/netopsiyon-dersleri"
touch notlar.txt
ls -l notlar.txt
touch bir.txt iki.txt

A newly created notlar.txt has a size of zero. It exists, but contains no text. The .txt suffix does not automatically add content or enforce what kind of bytes may be stored.

The last line supplies two separate targets. Touch normally finishes without listing each action, so we inspect the results with ls. Quote a filename if it contains spaces.

Touch the same file again

BASH
ls -l --full-time notlar.txt
touch notlar.txt
ls -l --full-time notlar.txt

GNU ls provides --full-time for more detailed timestamps. A minute-only listing may hide the difference between quick successive runs. These examples use GNU tools; formatting can differ elsewhere.

By default, touch updates access and modification timestamps. It does not append a line or clear existing text. After adding content with nano, repeat this experiment and confirm that the content remains.

It does not create missing parent directories

touch olmayan/not.txt fails if the parent directory does not exist. The special parent-creation behavior of mkdir -p does not apply to every file command.

Do not try to enter the resulting regular file with cd. Editing needs an editor; reading needs a reading tool. We will put actual text inside the file in the next lesson.

Separate the timestamp concepts

A regular file can have a content modification time, an access time and a status-change time, commonly called mtime, atime and ctime. Do not read ctime as creation time. Some filesystems additionally expose a birth time, but it is not presented identically everywhere.

Touch normally updates access and modification times, and the system may consequently update status-change information. This explains why a new-looking timestamp does not by itself establish when text was authored.

Select one timestamp

BASH
touch -a notlar.txt
touch -m notlar.txt

The -a option targets access time; -m targets modification time. Looking only at plain ls -l can hide the first change because that listing normally displays modification time. GNU ls -lu can display access time instead.

Reading the file can itself affect access information, subject to the filesystem's access-time policy. Do not assume every read immediately produces a visible timestamp change. Select the observation that matches the question.

Do not create a missing file: -c

BASH
touch -c bu-dosya-yok.txt
ls -l bu-dosya-yok.txt

Assume this sample name is initially absent. The -c option suppresses creation. Touch can finish successfully without making the file, and ls then reports it missing. A successful exit therefore does not always establish the existence of a target.

Use another file as a timestamp reference

BASH
touch -r notlar.txt bir.txt

The reference option copies timestamp information from notlar.txt to bir.txt. It does not copy the text. This can be useful in build or archive workflows, but is different from ordinary editing.

Remember shell expansion before using a pattern: touch *.txt can affect every matched file. Preview the names with ls -d before changing them, especially when your intention is to test only one file.

Finally reopen the populated notes in nano. Timestamp experiments must not have removed the saved lines. Contents and timestamp metadata are separate pieces of information.

A timestamp is not necessarily a birth date

The modification time shown by ls need not be the file's creation time. Touch can advance it without changing content. A recent timestamp alone therefore does not prove that the text was recently written.

Create deneme.txt, inspect its size, then touch it again. You still have one target file, not another copy. What changed is its timestamp information.

Previous lesson · Next lesson

References: GNU / Linux

Related Articles

Comments (0)

No comments yet. Be the first to comment!

Leave a Comment