Kali Linux

How to Use the touch Command in Linux

The touch command is one of the quickest ways to create new empty files or update timestamps for existing files in Linux. It’s widely used by system administrators, developers, and anyone who works with scripts or manages lots of files. Mastering touch can boost efficiency, automate file creation, and help maintain proper timestamp records.

What Does touch Do?

  • Instantly creates new files without opening a text editor.
  • Updates access and modification timestamps for files and directories.
  • Can selectively change only access or modification times.
  • Supports batch creation of multiple files at once.

Basic Syntax

touch [options] filename

Replace filename with your desired file or directory name. Include multiple names to create several files at once.

Practical Examples

1. Creating a Single Empty File

touch resume.txt

This command makes an empty file named resume.txt in the current folder.

2. Creating Multiple New Files

touch chapter1.md chapter2.md chapter3.md

Boom! Three files land in your directory, ready for editing.

3. Using Brace Expansion for Bulk Files

touch backup_{A,B,C}.tar.gz

Creates backup_A.tar.gzbackup_B.tar.gz, and backup_C.tar.gz at the same time.

4. Update Timestamps Without Creating a File

touch -c report.txt

Only updates timestamps if report.txt exists; doesn’t create it if it doesn’t.

5. Update Only Access or Modification Time

touch -a visitors.log      # Only access time
touch -m summary.docx      # Only modification time

6. Match Timestamps to Another File

touch -r old_version.txt new_version.txt

new_version.txt now has the same timestamps as old_version.txt.

7. Set a Custom Date/Time

touch -t 202510011200.00 archive.log

Set timestamps to October 1, 2025, 12:00:00.

Important Flags

OptionDescription
-aChange access time only
-mChange modification time only
-cDon’t create files if they don’t exist
-rSet times based on another file’s timestamps
-tSet a specific date/time (format: [[CC]YY]MMDDhhmm[.ss])

Why Use touch?

  • Perfect for creating log placeholders, batch file templates, or empty flags for scripts.
  • Useful for resetting modification times and simulating activity on system files.
  • Plays well with shell scripting for large-scale automation and DevOps workflows.

Read More: History of Linux

0xSnow

0xSnow is a cybersecurity researcher with a focus on both offensive and defensive security. Working with ethical hacking, threat detection, Linux tools, and adversary simulation, 0xSnow explores vulnerabilities, attack chains, and mitigation strategies. Passionate about OSINT, malware analysis, and red/blue team tactics, 0xSnow shares detailed research, technical walkthroughs, and security tool insights to support the infosec community.

Recent Posts

Microsoft Unveils “Project Helix”- A Next-Gen Xbox Merging Console and PC Gaming

Microsoft has officially unveiled its latest gaming venture, Project Helix, a next-generation gaming console set…

6 hours ago

Free Email Lookup Tools and Reverse Email Search Resources

In the digital era, an email address can reveal much more than just a contact…

7 hours ago

Mr.Holmes – A Comprehensive Guide To Installing And Using The OSINT Tool

Mr.Holmes is an OSINT (Open Source Intelligence) tool designed to gather valuable information from public…

7 hours ago

Whatweb – A Scanning Tool to Find Security Vulnerabilities in Web App

WhatWeb is the perfect name for this tool. It answers the question, “What is that…

7 hours ago

Whapa – Comprehensive Guide To The WhatsApp Forensic Toolset

In an era dominated by messaging apps, WhatsApp has become a key platform for personal…

8 hours ago

How OpenClaw Works

Imagine if you had a super-powered assistant who could automatically handle all the boring, repetitive…

1 week ago