How to move a file and change its creation time at the same time?
Clash Royale CLAN TAG#URR8PPP
up vote
2
down vote
favorite
If I move a file in Linux with the mv
command, it moves the file but doesn't change its creation time to the current time. For that purpose, I have to separately use the touch
command. So, is there a command that does both atomically?
I am interesting in doing this because I am using textFileStreaming in local mode (uses local file system instead of HDFS) with Spark, which requires atomic move of files in the streaming directory. If the time remains the same, as the original time for the moved file, the streaming program doesn't even notice it. It notices sure if through a script, I first move a file and then touch it to change its time. However, it could still happen, that the streaming program sees the file before its time was modified using touch, and thus ignore it.
linux files
add a comment |Â
up vote
2
down vote
favorite
If I move a file in Linux with the mv
command, it moves the file but doesn't change its creation time to the current time. For that purpose, I have to separately use the touch
command. So, is there a command that does both atomically?
I am interesting in doing this because I am using textFileStreaming in local mode (uses local file system instead of HDFS) with Spark, which requires atomic move of files in the streaming directory. If the time remains the same, as the original time for the moved file, the streaming program doesn't even notice it. It notices sure if through a script, I first move a file and then touch it to change its time. However, it could still happen, that the streaming program sees the file before its time was modified using touch, and thus ignore it.
linux files
1
Unix typically does not have a creation time. What filesystem is this, and what commands are you using?
â thrig
Oct 27 '17 at 20:13
Creation time, modification time or whatever you call it. The one that is displayed when you type ls -ll. My OS has ext4 filesystem. And like I said I am using 'mv' and 'touch'. But I want to do this in a single command, atomically that is.
â pythonic
Oct 27 '17 at 20:15
What if you touch and then move?
â Jesse_b
Oct 27 '17 at 20:19
That works too, but I still don't want that. Because maybe it take some time to move after the touch, and therefore the streaming handler still ignores it.
â pythonic
Oct 27 '17 at 20:22
rsync --remove-source-files SOURCEFILE DESTINATION/
will move your file and updatemtime
(thoughrsync
does use a hidden temporary file to do this...)
â don_crissti
Oct 27 '17 at 20:47
add a comment |Â
up vote
2
down vote
favorite
up vote
2
down vote
favorite
If I move a file in Linux with the mv
command, it moves the file but doesn't change its creation time to the current time. For that purpose, I have to separately use the touch
command. So, is there a command that does both atomically?
I am interesting in doing this because I am using textFileStreaming in local mode (uses local file system instead of HDFS) with Spark, which requires atomic move of files in the streaming directory. If the time remains the same, as the original time for the moved file, the streaming program doesn't even notice it. It notices sure if through a script, I first move a file and then touch it to change its time. However, it could still happen, that the streaming program sees the file before its time was modified using touch, and thus ignore it.
linux files
If I move a file in Linux with the mv
command, it moves the file but doesn't change its creation time to the current time. For that purpose, I have to separately use the touch
command. So, is there a command that does both atomically?
I am interesting in doing this because I am using textFileStreaming in local mode (uses local file system instead of HDFS) with Spark, which requires atomic move of files in the streaming directory. If the time remains the same, as the original time for the moved file, the streaming program doesn't even notice it. It notices sure if through a script, I first move a file and then touch it to change its time. However, it could still happen, that the streaming program sees the file before its time was modified using touch, and thus ignore it.
linux files
edited Oct 27 '17 at 21:01
guntbert
1,0011917
1,0011917
asked Oct 27 '17 at 20:07
pythonic
1112
1112
1
Unix typically does not have a creation time. What filesystem is this, and what commands are you using?
â thrig
Oct 27 '17 at 20:13
Creation time, modification time or whatever you call it. The one that is displayed when you type ls -ll. My OS has ext4 filesystem. And like I said I am using 'mv' and 'touch'. But I want to do this in a single command, atomically that is.
â pythonic
Oct 27 '17 at 20:15
What if you touch and then move?
â Jesse_b
Oct 27 '17 at 20:19
That works too, but I still don't want that. Because maybe it take some time to move after the touch, and therefore the streaming handler still ignores it.
â pythonic
Oct 27 '17 at 20:22
rsync --remove-source-files SOURCEFILE DESTINATION/
will move your file and updatemtime
(thoughrsync
does use a hidden temporary file to do this...)
â don_crissti
Oct 27 '17 at 20:47
add a comment |Â
1
Unix typically does not have a creation time. What filesystem is this, and what commands are you using?
â thrig
Oct 27 '17 at 20:13
Creation time, modification time or whatever you call it. The one that is displayed when you type ls -ll. My OS has ext4 filesystem. And like I said I am using 'mv' and 'touch'. But I want to do this in a single command, atomically that is.
â pythonic
Oct 27 '17 at 20:15
What if you touch and then move?
â Jesse_b
Oct 27 '17 at 20:19
That works too, but I still don't want that. Because maybe it take some time to move after the touch, and therefore the streaming handler still ignores it.
â pythonic
Oct 27 '17 at 20:22
rsync --remove-source-files SOURCEFILE DESTINATION/
will move your file and updatemtime
(thoughrsync
does use a hidden temporary file to do this...)
â don_crissti
Oct 27 '17 at 20:47
1
1
Unix typically does not have a creation time. What filesystem is this, and what commands are you using?
â thrig
Oct 27 '17 at 20:13
Unix typically does not have a creation time. What filesystem is this, and what commands are you using?
â thrig
Oct 27 '17 at 20:13
Creation time, modification time or whatever you call it. The one that is displayed when you type ls -ll. My OS has ext4 filesystem. And like I said I am using 'mv' and 'touch'. But I want to do this in a single command, atomically that is.
â pythonic
Oct 27 '17 at 20:15
Creation time, modification time or whatever you call it. The one that is displayed when you type ls -ll. My OS has ext4 filesystem. And like I said I am using 'mv' and 'touch'. But I want to do this in a single command, atomically that is.
â pythonic
Oct 27 '17 at 20:15
What if you touch and then move?
â Jesse_b
Oct 27 '17 at 20:19
What if you touch and then move?
â Jesse_b
Oct 27 '17 at 20:19
That works too, but I still don't want that. Because maybe it take some time to move after the touch, and therefore the streaming handler still ignores it.
â pythonic
Oct 27 '17 at 20:22
That works too, but I still don't want that. Because maybe it take some time to move after the touch, and therefore the streaming handler still ignores it.
â pythonic
Oct 27 '17 at 20:22
rsync --remove-source-files SOURCEFILE DESTINATION/
will move your file and update mtime
(though rsync
does use a hidden temporary file to do this...)â don_crissti
Oct 27 '17 at 20:47
rsync --remove-source-files SOURCEFILE DESTINATION/
will move your file and update mtime
(though rsync
does use a hidden temporary file to do this...)â don_crissti
Oct 27 '17 at 20:47
add a comment |Â
1 Answer
1
active
oldest
votes
up vote
4
down vote
mv
, if you are working within the same filesystem, does not alter the file itself, only its location. To alter the file, you need to use another utility such as touch
, or to simply cp
the file (which will create a new file with new modification and access times), and rm
the old one. If it's a particularly large file, this is inefficient, which is why tools like touch
exist in the first place.
Alternatively, if the problem is atomicity, you can move the file to a temporary location, touch
it, and then move it to its final resting place.
add a comment |Â
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
4
down vote
mv
, if you are working within the same filesystem, does not alter the file itself, only its location. To alter the file, you need to use another utility such as touch
, or to simply cp
the file (which will create a new file with new modification and access times), and rm
the old one. If it's a particularly large file, this is inefficient, which is why tools like touch
exist in the first place.
Alternatively, if the problem is atomicity, you can move the file to a temporary location, touch
it, and then move it to its final resting place.
add a comment |Â
up vote
4
down vote
mv
, if you are working within the same filesystem, does not alter the file itself, only its location. To alter the file, you need to use another utility such as touch
, or to simply cp
the file (which will create a new file with new modification and access times), and rm
the old one. If it's a particularly large file, this is inefficient, which is why tools like touch
exist in the first place.
Alternatively, if the problem is atomicity, you can move the file to a temporary location, touch
it, and then move it to its final resting place.
add a comment |Â
up vote
4
down vote
up vote
4
down vote
mv
, if you are working within the same filesystem, does not alter the file itself, only its location. To alter the file, you need to use another utility such as touch
, or to simply cp
the file (which will create a new file with new modification and access times), and rm
the old one. If it's a particularly large file, this is inefficient, which is why tools like touch
exist in the first place.
Alternatively, if the problem is atomicity, you can move the file to a temporary location, touch
it, and then move it to its final resting place.
mv
, if you are working within the same filesystem, does not alter the file itself, only its location. To alter the file, you need to use another utility such as touch
, or to simply cp
the file (which will create a new file with new modification and access times), and rm
the old one. If it's a particularly large file, this is inefficient, which is why tools like touch
exist in the first place.
Alternatively, if the problem is atomicity, you can move the file to a temporary location, touch
it, and then move it to its final resting place.
answered Oct 27 '17 at 20:31
DopeGhoti
40.7k54979
40.7k54979
add a comment |Â
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f400957%2fhow-to-move-a-file-and-change-its-creation-time-at-the-same-time%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
1
Unix typically does not have a creation time. What filesystem is this, and what commands are you using?
â thrig
Oct 27 '17 at 20:13
Creation time, modification time or whatever you call it. The one that is displayed when you type ls -ll. My OS has ext4 filesystem. And like I said I am using 'mv' and 'touch'. But I want to do this in a single command, atomically that is.
â pythonic
Oct 27 '17 at 20:15
What if you touch and then move?
â Jesse_b
Oct 27 '17 at 20:19
That works too, but I still don't want that. Because maybe it take some time to move after the touch, and therefore the streaming handler still ignores it.
â pythonic
Oct 27 '17 at 20:22
rsync --remove-source-files SOURCEFILE DESTINATION/
will move your file and updatemtime
(thoughrsync
does use a hidden temporary file to do this...)â don_crissti
Oct 27 '17 at 20:47