Use touch command to set modification time of a file to the Unix epoch
up vote
2
down vote
favorite
Edit: Better worded question: How do I only use the touch command to set the modification time of a file to the unix epoch?
I know that the unix epoch value can be retrieved using "data %s", but how do I use the touch command (and only that command) to set the modification time to the unix epoch?
Edit2:
So, I found that this runs without any errors:
touch -m -d ”@$(date +%s)” fileexample.txt
Is this a correct way of setting the modification time of a file to the Unix epoch?
Original Question (disregard)...:
Using the Linux manual for the “touch” command, show the command that you would
use to set the modification time of a file to the Unix epoch.
I understand that the Unix epoch is the amount of second (or miliseconds, I forgot) that has passed since the epoch (1970, January, 01)
What does the question mean by saying: setting the time "to the Unix epoch"?
So, Is it basically asking for today's time, or 1970 01 01, or...?
I know the command for this would be:
touch -m -t time file
But what time do I set it to?
Also, am I meant to use the unix epoch format for the time in the command?
linux date touch
New contributor
|
show 3 more comments
up vote
2
down vote
favorite
Edit: Better worded question: How do I only use the touch command to set the modification time of a file to the unix epoch?
I know that the unix epoch value can be retrieved using "data %s", but how do I use the touch command (and only that command) to set the modification time to the unix epoch?
Edit2:
So, I found that this runs without any errors:
touch -m -d ”@$(date +%s)” fileexample.txt
Is this a correct way of setting the modification time of a file to the Unix epoch?
Original Question (disregard)...:
Using the Linux manual for the “touch” command, show the command that you would
use to set the modification time of a file to the Unix epoch.
I understand that the Unix epoch is the amount of second (or miliseconds, I forgot) that has passed since the epoch (1970, January, 01)
What does the question mean by saying: setting the time "to the Unix epoch"?
So, Is it basically asking for today's time, or 1970 01 01, or...?
I know the command for this would be:
touch -m -t time file
But what time do I set it to?
Also, am I meant to use the unix epoch format for the time in the command?
linux date touch
New contributor
what have you tried?
– jsotola
2 days ago
@jsotola Well, I don't understand the question - or maybe I don't know enough about it. I can set it to the current time or to 1st January 1970 using -t 197001010000, but I don't know what I'm actually meant to do and I'm being very stupid right now.
– Mandingo
2 days ago
?????I don't understand the question
... is this a school assignment?
– jsotola
2 days ago
@jsotola Not exactly, but it's a question I was set to do in an introductory programme to Linux (There's a bunch of other questions, but I just don't exactly understand or know how to do this one as I'm a beginner in Linux and almost never used it before, and the wording is throwing me off.)
– Mandingo
2 days ago
read your own sentence above, the one starting withI understand ...
....... now think, when is unix epoch zero? ..... when is it 10? .... when is it 20? ......... is this correct ?1st January 1970 using -t 197001010000
– jsotola
2 days ago
|
show 3 more comments
up vote
2
down vote
favorite
up vote
2
down vote
favorite
Edit: Better worded question: How do I only use the touch command to set the modification time of a file to the unix epoch?
I know that the unix epoch value can be retrieved using "data %s", but how do I use the touch command (and only that command) to set the modification time to the unix epoch?
Edit2:
So, I found that this runs without any errors:
touch -m -d ”@$(date +%s)” fileexample.txt
Is this a correct way of setting the modification time of a file to the Unix epoch?
Original Question (disregard)...:
Using the Linux manual for the “touch” command, show the command that you would
use to set the modification time of a file to the Unix epoch.
I understand that the Unix epoch is the amount of second (or miliseconds, I forgot) that has passed since the epoch (1970, January, 01)
What does the question mean by saying: setting the time "to the Unix epoch"?
So, Is it basically asking for today's time, or 1970 01 01, or...?
I know the command for this would be:
touch -m -t time file
But what time do I set it to?
Also, am I meant to use the unix epoch format for the time in the command?
linux date touch
New contributor
Edit: Better worded question: How do I only use the touch command to set the modification time of a file to the unix epoch?
I know that the unix epoch value can be retrieved using "data %s", but how do I use the touch command (and only that command) to set the modification time to the unix epoch?
Edit2:
So, I found that this runs without any errors:
touch -m -d ”@$(date +%s)” fileexample.txt
Is this a correct way of setting the modification time of a file to the Unix epoch?
Original Question (disregard)...:
Using the Linux manual for the “touch” command, show the command that you would
use to set the modification time of a file to the Unix epoch.
I understand that the Unix epoch is the amount of second (or miliseconds, I forgot) that has passed since the epoch (1970, January, 01)
What does the question mean by saying: setting the time "to the Unix epoch"?
So, Is it basically asking for today's time, or 1970 01 01, or...?
I know the command for this would be:
touch -m -t time file
But what time do I set it to?
Also, am I meant to use the unix epoch format for the time in the command?
linux date touch
linux date touch
New contributor
New contributor
edited 2 days ago
Jeff Schaller
36.4k952120
36.4k952120
New contributor
asked 2 days ago
Mandingo
225
225
New contributor
New contributor
what have you tried?
– jsotola
2 days ago
@jsotola Well, I don't understand the question - or maybe I don't know enough about it. I can set it to the current time or to 1st January 1970 using -t 197001010000, but I don't know what I'm actually meant to do and I'm being very stupid right now.
– Mandingo
2 days ago
?????I don't understand the question
... is this a school assignment?
– jsotola
2 days ago
@jsotola Not exactly, but it's a question I was set to do in an introductory programme to Linux (There's a bunch of other questions, but I just don't exactly understand or know how to do this one as I'm a beginner in Linux and almost never used it before, and the wording is throwing me off.)
– Mandingo
2 days ago
read your own sentence above, the one starting withI understand ...
....... now think, when is unix epoch zero? ..... when is it 10? .... when is it 20? ......... is this correct ?1st January 1970 using -t 197001010000
– jsotola
2 days ago
|
show 3 more comments
what have you tried?
– jsotola
2 days ago
@jsotola Well, I don't understand the question - or maybe I don't know enough about it. I can set it to the current time or to 1st January 1970 using -t 197001010000, but I don't know what I'm actually meant to do and I'm being very stupid right now.
– Mandingo
2 days ago
?????I don't understand the question
... is this a school assignment?
– jsotola
2 days ago
@jsotola Not exactly, but it's a question I was set to do in an introductory programme to Linux (There's a bunch of other questions, but I just don't exactly understand or know how to do this one as I'm a beginner in Linux and almost never used it before, and the wording is throwing me off.)
– Mandingo
2 days ago
read your own sentence above, the one starting withI understand ...
....... now think, when is unix epoch zero? ..... when is it 10? .... when is it 20? ......... is this correct ?1st January 1970 using -t 197001010000
– jsotola
2 days ago
what have you tried?
– jsotola
2 days ago
what have you tried?
– jsotola
2 days ago
@jsotola Well, I don't understand the question - or maybe I don't know enough about it. I can set it to the current time or to 1st January 1970 using -t 197001010000, but I don't know what I'm actually meant to do and I'm being very stupid right now.
– Mandingo
2 days ago
@jsotola Well, I don't understand the question - or maybe I don't know enough about it. I can set it to the current time or to 1st January 1970 using -t 197001010000, but I don't know what I'm actually meant to do and I'm being very stupid right now.
– Mandingo
2 days ago
?????
I don't understand the question
... is this a school assignment?– jsotola
2 days ago
?????
I don't understand the question
... is this a school assignment?– jsotola
2 days ago
@jsotola Not exactly, but it's a question I was set to do in an introductory programme to Linux (There's a bunch of other questions, but I just don't exactly understand or know how to do this one as I'm a beginner in Linux and almost never used it before, and the wording is throwing me off.)
– Mandingo
2 days ago
@jsotola Not exactly, but it's a question I was set to do in an introductory programme to Linux (There's a bunch of other questions, but I just don't exactly understand or know how to do this one as I'm a beginner in Linux and almost never used it before, and the wording is throwing me off.)
– Mandingo
2 days ago
read your own sentence above, the one starting with
I understand ...
....... now think, when is unix epoch zero? ..... when is it 10? .... when is it 20? ......... is this correct ? 1st January 1970 using -t 197001010000
– jsotola
2 days ago
read your own sentence above, the one starting with
I understand ...
....... now think, when is unix epoch zero? ..... when is it 10? .... when is it 20? ......... is this correct ? 1st January 1970 using -t 197001010000
– jsotola
2 days ago
|
show 3 more comments
1 Answer
1
active
oldest
votes
up vote
4
down vote
accepted
-t
doesn't accept epoch time, -d
does
-d, --date=STRING
parse STRING and use it instead of current time
-t STAMP
use [[CC]YY]MMDDhhmm[.ss] instead of current time
You need to use -d
or --date
instead of -t
and you need to put @
before epochtime format is used, as described in date
manpages:
EXAMPLES
Convert seconds since the epoch (1970-01-01 UTC) to a date
$ date --date='@2147483647'
Example:
touch --date=@1442968132 test.txt
If you want to change modify time only, use -m
or --time modify
or --time mtime
, without it both modify and access times are changed.
-m change only the modification time
--time=WORD
change the specified time: WORD is access, atime, or use: equivalent to -a WORD is modify or mtime: equivalent to -m
Examples:
$ touch --date=@1442968132 test
$ stat test
File: test
Size: 0 Blocks: 0 IO Block: 4096 regular empty file
Device: fd03h/64771d Inode: 43266017 Links: 1
Access: (0664/-rw-rw-r--) Uid: ( 1000/ user1) Gid: ( 1000/ user1)
Context: unconfined_u:object_r:user_home_t:s0
Access: 2015-09-23 02:28:52.000000000 +0200
Modify: 2015-09-23 02:28:52.000000000 +0200
Change: 2018-11-23 11:34:59.893888360 +0100
Birth: -
$ touch --date=@1542968132 test
$ stat test
File: test
Size: 0 Blocks: 0 IO Block: 4096 regular empty file
Device: fd03h/64771d Inode: 43266017 Links: 1
Access: (0664/-rw-rw-r--) Uid: ( 1000/ user1) Gid: ( 1000/ user1)
Context: unconfined_u:object_r:user_home_t:s0
Access: 2018-11-23 11:15:32.000000000 +0100
Modify: 2018-11-23 11:15:32.000000000 +0100
Change: 2018-11-23 11:35:06.893888073 +0100
Birth: -
$ touch -m --date=@1342968132 test
$ stat test
File: test
Size: 0 Blocks: 0 IO Block: 4096 regular empty file
Device: fd03h/64771d Inode: 43266017 Links: 1
Access: (0664/-rw-rw-r--) Uid: ( 1000/ user1) Gid: ( 1000/ user1)
Context: unconfined_u:object_r:user_home_t:s0
Access: 2018-11-23 11:15:32.000000000 +0100
Modify: 2012-07-22 16:42:12.000000000 +0200
Change: 2018-11-23 11:35:22.300887441 +0100
Also, is touch -m -d ”@$(date +%s)” test.txt a correct way of doing it?
– Mandingo
2 days ago
1
yes if you want to change modify time only, without it it will change access time also
– rAlen
2 days ago
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
accepted
-t
doesn't accept epoch time, -d
does
-d, --date=STRING
parse STRING and use it instead of current time
-t STAMP
use [[CC]YY]MMDDhhmm[.ss] instead of current time
You need to use -d
or --date
instead of -t
and you need to put @
before epochtime format is used, as described in date
manpages:
EXAMPLES
Convert seconds since the epoch (1970-01-01 UTC) to a date
$ date --date='@2147483647'
Example:
touch --date=@1442968132 test.txt
If you want to change modify time only, use -m
or --time modify
or --time mtime
, without it both modify and access times are changed.
-m change only the modification time
--time=WORD
change the specified time: WORD is access, atime, or use: equivalent to -a WORD is modify or mtime: equivalent to -m
Examples:
$ touch --date=@1442968132 test
$ stat test
File: test
Size: 0 Blocks: 0 IO Block: 4096 regular empty file
Device: fd03h/64771d Inode: 43266017 Links: 1
Access: (0664/-rw-rw-r--) Uid: ( 1000/ user1) Gid: ( 1000/ user1)
Context: unconfined_u:object_r:user_home_t:s0
Access: 2015-09-23 02:28:52.000000000 +0200
Modify: 2015-09-23 02:28:52.000000000 +0200
Change: 2018-11-23 11:34:59.893888360 +0100
Birth: -
$ touch --date=@1542968132 test
$ stat test
File: test
Size: 0 Blocks: 0 IO Block: 4096 regular empty file
Device: fd03h/64771d Inode: 43266017 Links: 1
Access: (0664/-rw-rw-r--) Uid: ( 1000/ user1) Gid: ( 1000/ user1)
Context: unconfined_u:object_r:user_home_t:s0
Access: 2018-11-23 11:15:32.000000000 +0100
Modify: 2018-11-23 11:15:32.000000000 +0100
Change: 2018-11-23 11:35:06.893888073 +0100
Birth: -
$ touch -m --date=@1342968132 test
$ stat test
File: test
Size: 0 Blocks: 0 IO Block: 4096 regular empty file
Device: fd03h/64771d Inode: 43266017 Links: 1
Access: (0664/-rw-rw-r--) Uid: ( 1000/ user1) Gid: ( 1000/ user1)
Context: unconfined_u:object_r:user_home_t:s0
Access: 2018-11-23 11:15:32.000000000 +0100
Modify: 2012-07-22 16:42:12.000000000 +0200
Change: 2018-11-23 11:35:22.300887441 +0100
Also, is touch -m -d ”@$(date +%s)” test.txt a correct way of doing it?
– Mandingo
2 days ago
1
yes if you want to change modify time only, without it it will change access time also
– rAlen
2 days ago
add a comment |
up vote
4
down vote
accepted
-t
doesn't accept epoch time, -d
does
-d, --date=STRING
parse STRING and use it instead of current time
-t STAMP
use [[CC]YY]MMDDhhmm[.ss] instead of current time
You need to use -d
or --date
instead of -t
and you need to put @
before epochtime format is used, as described in date
manpages:
EXAMPLES
Convert seconds since the epoch (1970-01-01 UTC) to a date
$ date --date='@2147483647'
Example:
touch --date=@1442968132 test.txt
If you want to change modify time only, use -m
or --time modify
or --time mtime
, without it both modify and access times are changed.
-m change only the modification time
--time=WORD
change the specified time: WORD is access, atime, or use: equivalent to -a WORD is modify or mtime: equivalent to -m
Examples:
$ touch --date=@1442968132 test
$ stat test
File: test
Size: 0 Blocks: 0 IO Block: 4096 regular empty file
Device: fd03h/64771d Inode: 43266017 Links: 1
Access: (0664/-rw-rw-r--) Uid: ( 1000/ user1) Gid: ( 1000/ user1)
Context: unconfined_u:object_r:user_home_t:s0
Access: 2015-09-23 02:28:52.000000000 +0200
Modify: 2015-09-23 02:28:52.000000000 +0200
Change: 2018-11-23 11:34:59.893888360 +0100
Birth: -
$ touch --date=@1542968132 test
$ stat test
File: test
Size: 0 Blocks: 0 IO Block: 4096 regular empty file
Device: fd03h/64771d Inode: 43266017 Links: 1
Access: (0664/-rw-rw-r--) Uid: ( 1000/ user1) Gid: ( 1000/ user1)
Context: unconfined_u:object_r:user_home_t:s0
Access: 2018-11-23 11:15:32.000000000 +0100
Modify: 2018-11-23 11:15:32.000000000 +0100
Change: 2018-11-23 11:35:06.893888073 +0100
Birth: -
$ touch -m --date=@1342968132 test
$ stat test
File: test
Size: 0 Blocks: 0 IO Block: 4096 regular empty file
Device: fd03h/64771d Inode: 43266017 Links: 1
Access: (0664/-rw-rw-r--) Uid: ( 1000/ user1) Gid: ( 1000/ user1)
Context: unconfined_u:object_r:user_home_t:s0
Access: 2018-11-23 11:15:32.000000000 +0100
Modify: 2012-07-22 16:42:12.000000000 +0200
Change: 2018-11-23 11:35:22.300887441 +0100
Also, is touch -m -d ”@$(date +%s)” test.txt a correct way of doing it?
– Mandingo
2 days ago
1
yes if you want to change modify time only, without it it will change access time also
– rAlen
2 days ago
add a comment |
up vote
4
down vote
accepted
up vote
4
down vote
accepted
-t
doesn't accept epoch time, -d
does
-d, --date=STRING
parse STRING and use it instead of current time
-t STAMP
use [[CC]YY]MMDDhhmm[.ss] instead of current time
You need to use -d
or --date
instead of -t
and you need to put @
before epochtime format is used, as described in date
manpages:
EXAMPLES
Convert seconds since the epoch (1970-01-01 UTC) to a date
$ date --date='@2147483647'
Example:
touch --date=@1442968132 test.txt
If you want to change modify time only, use -m
or --time modify
or --time mtime
, without it both modify and access times are changed.
-m change only the modification time
--time=WORD
change the specified time: WORD is access, atime, or use: equivalent to -a WORD is modify or mtime: equivalent to -m
Examples:
$ touch --date=@1442968132 test
$ stat test
File: test
Size: 0 Blocks: 0 IO Block: 4096 regular empty file
Device: fd03h/64771d Inode: 43266017 Links: 1
Access: (0664/-rw-rw-r--) Uid: ( 1000/ user1) Gid: ( 1000/ user1)
Context: unconfined_u:object_r:user_home_t:s0
Access: 2015-09-23 02:28:52.000000000 +0200
Modify: 2015-09-23 02:28:52.000000000 +0200
Change: 2018-11-23 11:34:59.893888360 +0100
Birth: -
$ touch --date=@1542968132 test
$ stat test
File: test
Size: 0 Blocks: 0 IO Block: 4096 regular empty file
Device: fd03h/64771d Inode: 43266017 Links: 1
Access: (0664/-rw-rw-r--) Uid: ( 1000/ user1) Gid: ( 1000/ user1)
Context: unconfined_u:object_r:user_home_t:s0
Access: 2018-11-23 11:15:32.000000000 +0100
Modify: 2018-11-23 11:15:32.000000000 +0100
Change: 2018-11-23 11:35:06.893888073 +0100
Birth: -
$ touch -m --date=@1342968132 test
$ stat test
File: test
Size: 0 Blocks: 0 IO Block: 4096 regular empty file
Device: fd03h/64771d Inode: 43266017 Links: 1
Access: (0664/-rw-rw-r--) Uid: ( 1000/ user1) Gid: ( 1000/ user1)
Context: unconfined_u:object_r:user_home_t:s0
Access: 2018-11-23 11:15:32.000000000 +0100
Modify: 2012-07-22 16:42:12.000000000 +0200
Change: 2018-11-23 11:35:22.300887441 +0100
-t
doesn't accept epoch time, -d
does
-d, --date=STRING
parse STRING and use it instead of current time
-t STAMP
use [[CC]YY]MMDDhhmm[.ss] instead of current time
You need to use -d
or --date
instead of -t
and you need to put @
before epochtime format is used, as described in date
manpages:
EXAMPLES
Convert seconds since the epoch (1970-01-01 UTC) to a date
$ date --date='@2147483647'
Example:
touch --date=@1442968132 test.txt
If you want to change modify time only, use -m
or --time modify
or --time mtime
, without it both modify and access times are changed.
-m change only the modification time
--time=WORD
change the specified time: WORD is access, atime, or use: equivalent to -a WORD is modify or mtime: equivalent to -m
Examples:
$ touch --date=@1442968132 test
$ stat test
File: test
Size: 0 Blocks: 0 IO Block: 4096 regular empty file
Device: fd03h/64771d Inode: 43266017 Links: 1
Access: (0664/-rw-rw-r--) Uid: ( 1000/ user1) Gid: ( 1000/ user1)
Context: unconfined_u:object_r:user_home_t:s0
Access: 2015-09-23 02:28:52.000000000 +0200
Modify: 2015-09-23 02:28:52.000000000 +0200
Change: 2018-11-23 11:34:59.893888360 +0100
Birth: -
$ touch --date=@1542968132 test
$ stat test
File: test
Size: 0 Blocks: 0 IO Block: 4096 regular empty file
Device: fd03h/64771d Inode: 43266017 Links: 1
Access: (0664/-rw-rw-r--) Uid: ( 1000/ user1) Gid: ( 1000/ user1)
Context: unconfined_u:object_r:user_home_t:s0
Access: 2018-11-23 11:15:32.000000000 +0100
Modify: 2018-11-23 11:15:32.000000000 +0100
Change: 2018-11-23 11:35:06.893888073 +0100
Birth: -
$ touch -m --date=@1342968132 test
$ stat test
File: test
Size: 0 Blocks: 0 IO Block: 4096 regular empty file
Device: fd03h/64771d Inode: 43266017 Links: 1
Access: (0664/-rw-rw-r--) Uid: ( 1000/ user1) Gid: ( 1000/ user1)
Context: unconfined_u:object_r:user_home_t:s0
Access: 2018-11-23 11:15:32.000000000 +0100
Modify: 2012-07-22 16:42:12.000000000 +0200
Change: 2018-11-23 11:35:22.300887441 +0100
edited 2 days ago
answered 2 days ago
rAlen
655410
655410
Also, is touch -m -d ”@$(date +%s)” test.txt a correct way of doing it?
– Mandingo
2 days ago
1
yes if you want to change modify time only, without it it will change access time also
– rAlen
2 days ago
add a comment |
Also, is touch -m -d ”@$(date +%s)” test.txt a correct way of doing it?
– Mandingo
2 days ago
1
yes if you want to change modify time only, without it it will change access time also
– rAlen
2 days ago
Also, is touch -m -d ”@$(date +%s)” test.txt a correct way of doing it?
– Mandingo
2 days ago
Also, is touch -m -d ”@$(date +%s)” test.txt a correct way of doing it?
– Mandingo
2 days ago
1
1
yes if you want to change modify time only, without it it will change access time also
– rAlen
2 days ago
yes if you want to change modify time only, without it it will change access time also
– rAlen
2 days ago
add a comment |
Mandingo is a new contributor. Be nice, and check out our Code of Conduct.
Mandingo is a new contributor. Be nice, and check out our Code of Conduct.
Mandingo is a new contributor. Be nice, and check out our Code of Conduct.
Mandingo is a new contributor. Be nice, and check out our Code of Conduct.
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
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f483634%2fuse-touch-command-to-set-modification-time-of-a-file-to-the-unix-epoch%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
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
Required, but never shown
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
Required, but never shown
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
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
what have you tried?
– jsotola
2 days ago
@jsotola Well, I don't understand the question - or maybe I don't know enough about it. I can set it to the current time or to 1st January 1970 using -t 197001010000, but I don't know what I'm actually meant to do and I'm being very stupid right now.
– Mandingo
2 days ago
?????
I don't understand the question
... is this a school assignment?– jsotola
2 days ago
@jsotola Not exactly, but it's a question I was set to do in an introductory programme to Linux (There's a bunch of other questions, but I just don't exactly understand or know how to do this one as I'm a beginner in Linux and almost never used it before, and the wording is throwing me off.)
– Mandingo
2 days ago
read your own sentence above, the one starting with
I understand ...
....... now think, when is unix epoch zero? ..... when is it 10? .... when is it 20? ......... is this correct ?1st January 1970 using -t 197001010000
– jsotola
2 days ago