I need to touch a bunch of directories recursively. All the directories and their files, but I can't find any option in the touch command that allows this.
In the shell I have done touch /home/abcdefg/*
Which changes the dates on some files but does no go down into sub-directories, which is what I want.
Is there a way to do this that you know of?
Thank you in advance.
RobertRogers
7:19 pm on Oct 15, 2006 (gmt 0)
Is webmaster world only just adsense-ers?
mcavic
12:05 am on Oct 16, 2006 (gmt 0)
find /home/abcdefg/ -exec touch {} \;
The abcdefg directory itself will be included.
jtara
12:40 am on Oct 16, 2006 (gmt 0)
"find" is a fundamental of the Linux command-line toolkit!
So many commands have had a "recursive" option added, that we sometimes forget that find was once the only way to do this.
mcavic
1:27 am on Oct 16, 2006 (gmt 0)
Yes, and find -exec is usually more flexible than the recursive command.
RobertRogers
10:28 pm on Oct 17, 2006 (gmt 0)
Excellent guys, thank you very much :-)
RobertRogers
1:26 pm on Oct 18, 2006 (gmt 0)
So I could do this recursively like:
find /home -exec touch -t 200512163333.33 {} \;
For testing purposes, how could I generate a random number for the date, so that each file has a different random number associated with it?
mcavic
3:17 pm on Oct 18, 2006 (gmt 0)
You'd need an external program to give you a random number in the correct valid date format, then do something like:
find /home -exec touch -t `random` {} \;
It's not necessary to do that to test find, though. Just touch them all with the same date, then if they all have the new date, it worked.