Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I have two files new.txt and old.txt. In the end of my script I want to rename these files, old.txt -> old_1.txt and new.txt -> old.txt. These are two lines of my script:

mv old.txt old_1.txt
mv new.txt old.txt

My question is, if it is safe to use these two mv commands and if there is not possible, that second mv command will be executed (in some specific condition) earlier than first?

The script is executed once a day, and I noticed that old_1.txt has date of modification from previous day (it wasn't replaced). However if I have run this script manually, the old_1.txt has been modified already. Could someone explain me, where could be a problem?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
389 views
Welcome To Ask or Share your Answers For Others

1 Answer

The command mv will use the date of new.txt for old.txt. When you say you run the script manually I assume you are creating new.txt (or you have opened new.txt with some text editor that has saved) thus having todays date. when you run mv on this new new.txt it will cause old.txt to have todays date.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...