Looking at your question again, I had it in reverse. My code was moving all files create AFTER the one in question. Does "created" mean also "modified". In UNIX, you don't actually know when a file was "created". You just know when the data was modified and when the meta-file info ("
inode") was modified. If you change the file's permissions or ownership, you will change the meta-file info.
My code also renamed the files with the number of seconds since 1970, rather than in the format you wanted. So, improving on my original version:
Code:
get_filetime()
{
find . -name "$1" -printf "%TY%Tm%Td%TH%TM%TS\n"
}
cd $TARGET_DIR
touch __stop__$$
ls -lt | grep '^-' | awk '/__stop__'$$'$/ { start=1 } start,0' |
while read file; do
filetime=`get_filetime $file`
mv $file $NEWDIR/$file_$filetime
done
rm -f __stop__$$