You can use the touch
command along with the -r
switch to apply another file's attributes to a file.
NOTE: There is no such thing as creation date in Unix, there are only access, modify, and change. See this U&L Q&A titled: get age of given file for further details.
$ touch -r goldenfile newfile
Example
For example purposes here's a goldenfile
that was created with some arbitrary timestamp.
$ touch -d 20120101 goldenfile
$ ls -l goldenfile
-rw-rw-r--. 1 saml saml 0 Jan 1 2012 goldenfile
Now I make some new file:
$ touch newfile
$ ls -l newfile
-rw-rw-r--. 1 saml saml 0 Mar 7 09:06 newfile
Now apply goldenfile
's attributes to newfile
.
$ touch -r goldenfile newfile
$ ls -l goldenfile newfile
-rw-rw-r--. 1 saml saml 0 Jan 1 2012 newfile
-rw-rw-r--. 1 saml saml 0 Jan 1 2012 goldenfile
Now newfile
has the same attributes.
Modify via Samba
I just confirmed that I'm able to do this using my Fedora 19 laptop which includes version 1.16.3-2 connected to a Thecus N12000 NAS (uses a modified version of CentOS 5.x).
I was able to touch a file as I mentioned above and it worked as I described. Your issue is likely a problem with the either the mounting options being used, which may be omitting the tracking of certain time attributes, or perhaps it's related to one of these bugs:
With the zsh
shell:
tail -n 5 ./*.aff(D.om[1])
With other shells, it's quite difficult to come up with something reliable if you don't want to make assumptions on what file names may contain.
For instance, the bash
equivalent, if you're on a recent GNU system would be:
find . -maxdepth 1 -name '*.aff' -type f -printf '%T@:%p\0' |
sort -rzn |
sed -zn 's/[^:]*://p;q' |
xargs -r0 tail -n 5
Or:
find . -maxdepth 1 -name '*.aff' -type f -printf '%T@/%p\0' |
sort -rzn | (IFS=/ read -rd '' mtime file && tail -n 5 "$file")
Best Answer
The simplest : you could use :
to give THEFILE the same time as Referencefile so:
But if you prefer to have a more flexible way:
To have a "reliable" way to get the time of a file in a "portable" format, not depending on if the file last changed within 6 months, etc:
so you could do this to get a time suitable for touch: