Glenn
Glenn

Reputation: 551

BASH script. How to touch every file before a specified modify date

So I want to be able to go into a folder and update "last modified" data on every file within.

So far, I think I should be using:

touch --date "2012-12-31" /tmp/date
find /filestotouch -type f -not -newer /tmp/date

And this should list all the files that match. Now, do I need to make a loop, or is there a simple way to pass this data to touch and have it do them all?

Upvotes: 0

Views: 1780

Answers (2)

Aaron Digulla
Aaron Digulla

Reputation: 328604

There are two options:

  1. Add the option -exec: ... -not -newer /tmp/date -exec touch "{}" \;
  2. Pipe to xargs: ... -not -newer /tmp/date -print0 | xargs -0 touch

Upvotes: 3

user626607
user626607

Reputation:

Try the find command:

find /filestotouch -iname "*.type" -mtime +60 -exec touch "{}" \;

The above commands will extract all the files that were modified 60 days back.

Upvotes: 1

Related Questions