101-500 practice question 11 of 30

Which of the following commands will NOT update the modify timestamp on the file /tmp/myfile.txt?

Full set: 246 questions
Answer options
A: file /tmp/myfile.txt Correct answer
B: echo "Hello" >/tmp/myfile.txt
C: sed -ie "s/1/2/" /tmp/myfile.txt
D: echo -n "Hello" >>/tmp/myfile.txt
E: touch/tmp/myfile.txt
Correct Answer:
A. file /tmp/myfile.txt
Explanation

The file command is a read-only utility that inspects a file's content to determine its type. This action only requires reading the file, which may update the access timestamp (atime) but does not modify the file's data or its metadata. Therefore, the modification timestamp (mtime) remains unchanged. All other options involve writing to the file, either by overwriting, appending, in-place editing, or explicitly updating timestamps, all of which change the mtime.

Why Incorrect

B. echo "Hello" >/tmp/myfile.txt: The > redirection operator overwrites the file's content, which is a modification that updates mtime.
C. sed -ie "s/1/2/" /tmp/myfile.txt: The sed -i command edits the file in-place, directly modifying its content and thus updating mtime.
D. echo -n "Hello" >>/tmp/myfile.txt: The >> redirection operator appends data to the end of the file, which is a modification that updates mtime.
E. touch /tmp/myfile.txt: The touch command's primary function is to update a file's access and modification timestamps to the current time.

References

1. Free Software Foundation. (2020). GNU Coreutils Manual. Section 27.1, "touch: Change file timestamps". Retrieved from https://www.gnu.org/software/coreutils/manual/htmlnode/touch-invocation.html

2. Linux man-pages project. (2021). stat(2) — get file status. "The stmtime field is the time of the last modification of file data." Retrieved from https://man7.org/linux/man-pages/man2/stat.2.html

3. Linux man-pages project. (2021). file(1) — determine file type. The description outlines a read-only inspection process. Retrieved from https://man7.org/linux/man-pages/man1/file.1.html

Scroll to Top