Setting File Modification Time with touch

How can you make a file quickly (often for some kind of test)? In the Bourne shell, use the command below. Because this command uses a built-in () operator, it's fast and efficient. This creates a new file or empties an existing file:

$ > filename

The C shell doesn't allow that. From the C shell, you can empty a file by copying /dev/null onto it (). The easiest way to create an empty file is with the touch command. touch is also useful from any shell to change an existing file's modification time to "now"-without changing the file's contents (usually for an automatic file time comparison (, , )). You can touch more than one file at a time. Just type:

% touch filename1 filename2 ...


touch Some versions of touch (including the GNU version on the tutorial) can create a file with an arbitrary timestamp. That is, you can use touch to make a file that's backdated to any point in the past (or, for that matter, postdated to some point in the future). If your version can do that, the syntax is probably like:


% touch date filename1 filename2 ...

where date has the form:

modyhrmiyy

and:

For example, to create a file dated 4 p.m., March 20 of this year, give the command:

% touch 03201600 foo

If you don't want to use a different timestamp (that is, you want the current time) and the filename starts with a digit, touch might think that the filename is a time and complain "date: bad conversion." To start a filename with a digit, use a relative pathname that starts with a (dot) (). For example, to make a file in the current directory:

% touch ./123456

Article explains cpmod, a program on the tutorial for copying dates and permissions from file to file.

- ML, JP