I am wondering how to change the time format when I am modifying a time with the touch command in the c shell.

For example I need to use

touch -a -t 051512002015 file.txt

This will change the access time to May 15th 2015, 12:00.

What I want to do though is (notice year is first now)

touch -a -t 201505151200 file.txt

This is how touch works in Linux. I use UnxUtils on Windows, which I am almost sure uses c-shell touch. I want the commands to be consistent. Is it possible to change the c-shell touch command?

2 Answers 2


This isn't about the shell, touch is an external program.

There were historically two syntaxes for the date argument to touch:

touch -t CCYYMMDDhhmm.SS    # CC or CCYY may be omitted; .SS may be omitted
touch MMDDhhmmYY            # YY may be omitted

The command appeared in Unix Seventh edition with no date argument. BSD versions acquired the -t option (with all the date components in descending order) somewhere around 4.4BSD. System V (e.g. SunOS 4.1.3) had the straight-date form with the year at the end. By the time of Single Unix v2 (based on POSIX:1992), the System V form was considered obsolescent, and it is no longer included in Single Unix v3 (POSIX:2001).

I recommend using the standard (BSD) syntax in your script. On the legacy systems that require the BSD syntax, arrange to have a compatible touch. Several approaches are possible:

  • Write a wrapper function that shuffles the arguments around if it detects that your script is running on a legacy system.
  • Arrange to have a PATH that puts the standard-compliant directories ahead of the legacy directories.
  • (You may get more specific advice if you post the exact legacy variants and versions you need to support.)
  • Thank you this is very helpful. I am using UnxUtil the Windows open source program that emulates Unix commands. This is why it could get a little fuzzy, and I'm not quite sure how to figure out what version UnxUtil uses.
    – Jerron
    Commented Apr 7, 2011 at 10:38

The touch command is not a part of any shell that I am aware of. At least according to my man page for both tcsh and bash, touch is not mentioned. Instead touch is it's own command. The touch command on Linux and *BSD will be slightly different, that's unavoidable, but you can write a wrapper around it if needed. However, at first glance, the -t argument seems to be identical on both my Ubuntu Linux machine and my FreeBSD machine. Here is the format according to the man page for touch on Ubuntu Linux 8.04:

touch [-t [[CC]YY]MMDDhhmm[.ss]]

And on the man page on FreeBSD:

touch [-t [[CC]YY]MMDDhhmm[.SS]]

I'm not sure where your odd time format for touch comes but look below. The FreeBSD man page also goes into more detail about what those letters mean, but it's identical to the format used by Ye old date command used on FreeBSD:

date [-jnu] [[[[[CC]YY]MM]DD]hh]mm[.ss]

It's actually the same format as both touch commands. Oddly, though on Linux, they used a different and obscure format on the date command for some unknown reason:

date [MMDDhhmm[[CC]YY][.ss]]

I have no idea why Linux put the year for date in-between the minutes and the seconds. In case it's not clear, heres what the letters mean in all these commands:

  • CC - Century (00-99)
  • YY - Year of Century (00-99)
  • MM - Month (01-12)
  • DD - Day of month (01-31)
  • hh - Hour (00-23)
  • mm - Minute (00-59)
  • ss - Seconds (00-61) (yes, 61, not 59)
  • I may be mistaken, I use UnxUtil on Windows and for whatever shell that emulates is what I need. I am not sure how to figure that out and documentation is lacking.
    – Jerron
    Commented Apr 6, 2011 at 21:10

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .