touch -t
normally only changes the modification and access times. It only changes the creation time if the target time is before the original creation time.
touch -t 199912312359 file.txt
touch -t $(date -jf %FT%T 1999-12-31T23:59:59 +%Y%m%d%H%M%S) file.txt
SetFile -d
always changes the creation time.
SetFile -d '12/31/1999 23:59:59' file.txt
SetFile -d "$(GetFileInfo -m test.txt)" file.txt
SetFile is part of the command line tools package which can be downloaded from developer.apple.com/downloads or from Xcode's preferences.
Any file or folder that begins with '.' is going to be hidden in the Finder. That has always been true, back to the days of NeXTStep.
If what you are trying to do is automatically rename files that begin with a '.' to not begin with a '.' that can easily be accomplished with a shell script. Save the following as /usr/local/bin/rename-dot-files.sh
:
#!/bin/zsh -f
DIR="$HOME/Downloads/"
cd "$DIR"
ls -1Ad \.* | egrep -v '.DS_Store|.localized' | while read line
do
NEWNAME=$(echo "$line" | sed 's#^\.##g')
/bin/mv -vn "$line" "$NEWNAME"
done
exit 0
That script will look in $HOME/Downloads/
for any files that start with a . (excluding .DS_Store and .localized which you do not want to rename) and will rename it to the same name, without the '.' as long as there is no other file/folder with that same name.
To do this automatically you will need to create a launchd
plist that will automatically launch any time the directory changes:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Disabled</key>
<false/>
<key>Label</key>
<string>com.tjluoma.rename-dot-files</string>
<key>Program</key>
<string>/usr/local/bin/rename-dot-files.sh</string>
<key>RunAtLoad</key>
<true/>
<key>WatchPaths</key>
<array>
<string>/Users/luomat/Downloads/</string>
</array>
</dict>
</plist>
Obviously you'll want to change the path from /Users/luomat/
to whatever your $HOME is.
Save that plist to ~/Library/LaunchAgents/com.tjluoma.rename-dot-files.plist
and then load it as:
launchctl load ~/Library/LaunchAgents/com.tjluoma.rename-dot-files.plist
The script will run whenever the ~/Downloads/ is changed, which includes any files being added or removed, but it automatically limits itself to files which begin with '.'
Best Answer
You're lucky because the numbers in your file names are in just the order
touch -t
needs.This command in the terminal will work. You just need to make sure your working directory is set to the folder you want to do:
To break it down:
for f in *
sets the variablef
to the name of each file in the directory, in turn.do
puts everything until thedone
into thefor
loop.t=$(…)
sets the variablet
to the output of the commands in the parentheses.The first
sed
command matches any letters before a-
symbol, the-
;
and thespace
symbols, and the file extension, and deletes them.The second
sed
command inserts a period between the mm and ss values, as touch requires.touch -t $t $f
changes the file modification and creation times to the value oft
on the filef
.Tested on some dummy files with whatever version of
sed
ships with Mavericks.