2

I'm trying to add one year to the modification and creation dates to all files of a folder.

I found many examples to modify a whole date (not only the year).

How can I add one year to the creation/modification to all files in a folder?

I'm on OS X.

2
  • 3
    Which OS and filesystem are you using? Depending on that, you probably won't be able to modify or even get the creation time. Commented Jun 29, 2019 at 17:27
  • 1
    @muru I'm on OS X Commented Jun 29, 2019 at 17:37

2 Answers 2

4

touch has an adjust option (-A), but that is sadly limited to 99 hours, 99 minutes, and 99 seconds. But repeated applications can get you what you want:

in Bash:

# assume a year is 365 days for day in {1..365}; do touch -A 240000 folder/* done # on a mac with Xcode cmdline tools installed, # set creation time to mtime: for f in folder/* ; do SetFile -d "$(GetFileInfo -m $f)" $f done 
9
  • 1
    Thank you for your answer. I'm on OS X and this command didn't work :( Commented Jun 29, 2019 at 17:37
  • 1
    I'm on macOS as well. It works for me. In what way did it not work? Error message? Commented Jun 29, 2019 at 17:40
  • 1
    My bad : I only typed -A 240000 without the loop. Thank you ! your script is awesome. Commented Jun 29, 2019 at 17:42
  • 1
    I noticed that only the modification date is modified. How it's possible to modify the creation date as well? Commented Jun 29, 2019 at 17:44
  • 1
    @oya2020 use SetFile for that: apple.stackexchange.com/a/99599/205028 Commented Jun 29, 2019 at 17:47
1

If you're using GNU date, you can try something like

for file in *; do echo "$file" $(date -d "$(date -r $file) 1 year"); done 

(this really ought to be cleaned up for special characters and formatting) You're not going to get creation date on most file systems.

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.