nerdexam
CompTIA

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.

GNU and Unix Commands

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)
  • A
    79% (19)
  • C
    4% (1)
  • D
    4% (1)
  • E
    13% (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.

Afile /tmp/myfile.txtCorrect

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.

Becho "Hello" >/tmp/myfile.txt

The > redirection operator truncates and overwrites the file with new content, which updates the modify timestamp.

Csed -ie "s/1/2/" /tmp/myfile.txt

sed -ie performs an in-place edit, writing the substituted content back to the file and updating mtime.

Decho -n "Hello" >>/tmp/myfile.txt

The >> append operator writes new data to the end of the file, which modifies the file content and updates mtime.

Etouch /tmp/myfile.txt

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

#timestamp#file command#touch#modify time

Community Discussion

No community discussion yet for this question.

Full LX0-103 Practice