Home > Net >  find command to delete all files with specific last modified date
find command to delete all files with specific last modified date

Time:02-26

touch -m -d @$(( $(stat -c %Y file.txt) - 7200 )) file.txt

This command sets the last modified date on a single file. How could I edit it to use find to set a predefined last modified date, e.g. Dec 25, 2020, on all files in a folder and its subfolders?

CodePudding user response:

The command in the question makes a relative adjustment, subtracting two hours from the file's timestamp. If you're satisfied with a fixed timestamp then use:

find . -exec touch -t 201303101513 {}  

CodePudding user response:

This changes the Last Modified Date in folders and subfolders:

find -print | while read filename; do
    touch -t 201303101513 "$filename"
done

... I hope it helps others

  • Related