LX0-103 · Question #19
Which of the following commands will NOT update the modify timestamp on the file /tmp/myfile.txt?
The correct answer is A. file /tmp/myfile.txt. The file command reads a file only to detect its type and does not write to it, so it leaves the modify timestamp (mtime) unchanged.
Question
Which of the following commands will NOT update the modify timestamp on the file /tmp/myfile.txt?
Options
- Afile /tmp/myfile.txt
- Becho "Hello" >/tmp/myfile.txt
- Csed -ie "s/1/2/" /tmp/myfile.txt
- Decho -n "Hello" >>/tmp/myfile.txt
- Etouch /tmp/myfile.txt
How the community answered
(24 responses)- A79% (19)
- C4% (1)
- D4% (1)
- E13% (3)
Why each option
The file command reads a file only to detect its type and does not write to it, so it leaves the modify timestamp (mtime) unchanged.
The file command inspects file content to determine its type but performs only a read operation - it never writes to the file. Because mtime is updated only when file contents are modified, file leaves mtime untouched. It may update the access time (atime) depending on mount options, but the modify timestamp remains unchanged.
The > redirection operator truncates and overwrites the file with new content, which updates the modify timestamp.
sed -ie performs an in-place edit, writing the substituted content back to the file and updating mtime.
The >> append operator writes new data to the end of the file, which modifies the file content and updates mtime.
touch explicitly sets the access and modify timestamps of the file, updating mtime by design.
Concept tested: Linux file timestamps and read-only command behavior
Source: https://man7.org/linux/man-pages/man1/file.1.html
Topics
Community Discussion
No community discussion yet for this question.