LFCS · Question #832
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 only reads file metadata and content to determine its type, thus it does not alter the file or its modification timestamp. All other options involve writing or explicitly touching the file, which updates the timestamp.
Question
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
(45 responses)- A91% (41)
- B2% (1)
- D4% (2)
- E2% (1)
Why each option
The `file` command only reads file metadata and content to determine its type, thus it does not alter the file or its modification timestamp. All other options involve writing or explicitly touching the file, which updates the timestamp.
The `file` command is used for identifying file types and only reads the file's content and metadata without making any modifications. Therefore, executing `file /tmp/myfile.txt` will not update the modification timestamp of the file.
Redirecting output with `echo "Hello" >/tmp/myfile.txt` truncates and writes new content to the file, which is a modification and updates the modification timestamp.
The `sed -ie "s/1/2/" /tmp/myfile.txt` command with the `-i` option modifies the file in place, changing its content and consequently updating its modification timestamp.
Appending output with `echo -n "Hello" >>/tmp/myfile.txt` modifies the file by adding content, which updates its modification timestamp.
The `touch /tmp/myfile.txt` command's primary function is to update the access and/or modification timestamps of a file to the current time.
Concept tested: Linux file timestamp modification
Source: https://man7.org/linux/man-pages/man1/file.1.html
Topics
Community Discussion
No community discussion yet for this question.