الفلاتر
طريقة البحث
  • الكلمات العادية تجد الأسماء والنصوص والأمثلة.
  • "كلمتان" تجد العبارة بالضبط.
  • --name أو -x تجد خيارًا.
  • #كلمة تبحث داخل الأوامر فقط.
  • @grep تجد الدروس والمعامل التي تستخدم grep.
  • الفلاتر: cat:network · in:labs · level:rhcsa · ch:8 · root:yes. ضع ! قبل كلمة لاستبعادها. OR بين الكلمات تعني إحداها.
  • ↑ ↓ للتنقل · Enter للفتح · Esc للإغلاق · / للبحث

touch

Create an empty file, or change the access and modification times of a file.

المستوى
امتحان RHCSA
المجموعة
الملفات والمجلدات
يحتاج root
لا
الحزمة
coreutils

هذا الجزء لم يُترجم بعد. أنت ترى النص الإنجليزي.

ماذا يفعل

touch FILE creates FILE when it does not exist. When it exists, touch sets its times to now, without changing the content.

This is used to make test files, to create flag files that other programs look for (like /.autorelabel for SELinux), and to set exact times for tests of backup or cleanup scripts.

طريقة الكتابة

touch [OPTION]... FILE...

الخيارات 11

الأكثر استخدامًا

-a
Change only the access time.
-m
Change only the modification time.
-c, --no-create
Do not create files that do not exist.
-d, --date=text
Use this date and time instead of now, like "2026-01-31 14:00" or "yesterday".
-t stamp
Use this time in the form [[CC]YY]MMDDhhmm[.ss].
-r, --reference=file
Use the times of this other file.
-h, --no-dereference
Change the link itself, not the file it points to.
--time=word
Which time to change: access (atime) or modify (mtime).
-f
Ignored (kept for compatibility).
--help
Show help.
--version
Show the version.

أمثلة 11

$ مستخدم عادي# بصلاحية root (أو مع sudo)

  1. 1Create an empty file

    touch notes.txt

    If it already exists, only its time changes.

  2. 2Create many files at once

    touch file{1..5}.txt

    Makes file1.txt to file5.txt. Good for practice.

  3. 3Ask SELinux to relabel the whole system at the next boot

    touch /.autorelabel

    Needed after a root password reset with rd.break, or after SELinux was disabled.

  4. 4Set a file to an old date to test a cleanup script

    touch -d "40 days ago" /tmp/test-old.log
    find /tmp -name "*.log" -mtime +30

    The file looks 40 days old, so your find -mtime +30 test can find it.

  5. 5Give a file the same time as another file

    touch -r original.conf copy.conf

    Keeps times equal, for example after you fix a copy.

  6. 6Set an exact time with -t

    touch -t 202601011200 newyear.txt

    2026-01-01 12:00.

  7. 7Change only the access time

    touch -a report.pdf

    The modification time stays the same.

  8. 8Do not create a missing file

    touch -c maybe.txt

    No error and no new file if it does not exist.

  9. 9Create a flag file for a maintenance window

    touch /etc/nologin

    While this file exists, normal users cannot log in (root still can). Remove it after the work.

  10. 10Make an empty log file with the right owner

    touch /var/log/myapp.log && chown myapp: /var/log/myapp.log

    The service can write to it at its first start.

  11. 11Check if a folder is writable in a script

    touch /mnt/nfs/.write-test && rm /mnt/nfs/.write-test && echo "writable"

    A simple test before a backup job writes to a share.

انتبه

  • touch on an existing file does not empty it. To empty a file use > file or truncate -s 0 file.
  • Changing times can hide what really happened on a system; in forensics, look at ctime (it cannot be set by touch).

نصائح للحفظ

  • New empty file or "update the time" — both are touch.
  • /.autorelabel = SELinux relabel at the next boot.