开发者

recursive timestamp update in unix

When I create a directory say d1 and after 5 seconds d1/d2, then d1 timestamp gets updated to that of d2. After 5 seconds, when I create d1/d2/d3, only d2 timestamp gets updated to d3 but not that of d1.

Basically, my requirement is that not only the parent folder but all the folders from root to parent fo开发者_如何学Golder must get updated with the time of the parent folder.

Is there any way to update the timestamp of d1 with that of d3?

Please clarify.


find . -type d -exec touch -m -r d3 {}\;

Finds all directories in the current directory and updates the timestamp to the current time...


find . -type d -exec touch  -r d1/d2/d3 -m {} \;
touch options:
-r :reference file. The timestamp of this ref file will be used for touching.
-m :change the modification time.

This will find all the directories under pwd, and will modify the modification time of each to the modification time of d1/d2/d3 directory. It is assumed that you are in the directory that has directory d1.


This will set the modification time of only the directories that are on the path to the added file.

So in this tree

d1
d1/d2
d1/d2/d3  <-- this is the one we are adding
d1/d2a
d1/d2a/d3a

Only d1 and d1/d2 will be affected.

CHILD="d1/d2/d3"
DIR=`dirname "$CHILD"`
while [[ "$DIR" != "." ]]
do
    touch -m -r "$CHILD" "$DIR"
    DIR=`dirname "$DIR"`
done
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜