Change file timestamps, change the access and/or modification times of the specified files.

      touch [options]... File...


        Change the access time only.

        Do not create files that do not exist.

        Use time instead of the current time.  It can contain month names,
        timezones, 'am' and 'pm', etc.

   -f   Ignored; for compatibility with BSD versions of 'touch'.

   -h, --no-dereference
        Affect each symbolic link instead of any referenced file
        (useful only on systems that can change the timestamps of a symlink) 

        Change the modification time only.

   -r FILE
        Use the times of the reference FILE instead of the current time.

   -t [[CC]YY]MMDDhhmm[.ss]
        Set to a specific date/time.

   --help     Display help and exit

   --version  Output version information and exit

The -t argument will accept four-digit or two-digit years, specifying the seconds is optional. If no digits of the year are specified, the argument is interpreted as a date in the current year.

The --date=STRING is a mostly free format human readable date string such as "Sun, 29 Feb 2004 16:21:42 -0800" or "2004-02-29 16:21:42" or even "next Thursday". A date string may contain items indicating calendar date, time of day, time zone, day of week, relative time, relative date, and numbers. An empty string indicates the beginning of the day.

If two-digit year is specified, then CC is 20 for years in the range 0 ... 68, and 19 for year in 69 ... 99.

If the first FILE would be a valid argument to the '-t' option and no timestamp is given with any of the '-d', '-r', or '-t' options and the '--' argument is not given, that argument is interpreted as the time for the other files instead of as a file name.

Any FILE that does not exist is created empty.

If changing both the access and modification times to the current time, 'touch' can change the timestamps for files that the user running it does not own but has write permission for. Otherwise, the user must own the files.


Create/datestamp one file called sample.txt:

touch sample.txt

or in a subfolder:

touch "some folder/sample.txt"

Create a file sample.txt dated as 1958-12-31@14:30:

$ touch -t 195812311430 sample.txt

Create a file sample.txt dated as 2050-12-31@09:30:

$ touch -t 205012310930 sample.txt

Using brace expansion, create/datestamp 10 files called project1, project2 etc:

touch project{1,2,3,4,5,6,7,8,9,10}

Create/datestamp 100 files called file1, file2 etc:

for i in $(seq 1 100); do echo -n "file${i} "; touch file${i} 2>&1; done

“If you play it safe you stagnate is this league. Maybe we’ll bust, but if we hit it, we’ll hit it big” ~ Jimmy Johnson, coach of the Miami Dolphins

Related Linux commands

chgrp - Change group ownership.
chmod - Change access permissions.
chown - Change file owner and group.
date - Display or change the date.
mkdir - Create new folder(s).
rm - Delete files and folders.
which - Show full path of commands.
Equivalent Windows commands: TOUCH - Change file timestamps.

Copyright © 1999-2024
Some rights reserved