0

I would like to clone only the create date and the filenames in source and destination are different. The name part of it is the same, it's the extension that isn't. AVI videos in one directory, MP4 in another.

So I wanted to use touch --reference=file1 file2.

works great on one file but I have about 100. I do have a text file containing all the source filenames. Oh and lots of them have spaces and apostrophes in them too.

0
0

Something like this?

for avi in *.avi
do
    mp4="${avi%%.avi}".mp4
    if [ -e "$mp4" ]
    then
        touch --reference="$avi" "$mp4"
    fi
done
0
0

The time that your are changing with touch is not the file creation time, but rather the modification time (up-to-date Linux filesystems do support file creation time, but this is kind of useless as currently you need special tools to access it).

To change the file modification times as asked in bash, you can use a loop like this from within the directory containing the reference files:

for ref_file in *.avi; do
  touch -c --reference="$ref_file" "target_dir/${ref_file%avi}mp4"
done
1
  • aha... thanks. at first I stupidly used mp4/ not ../mp4 for the target_dir and it didn't work. – shred Apr 4 '14 at 20:14

Not the answer you're looking for? Browse other questions tagged or ask your own question.