Walker News

Linux: How To Display File Change Timestamp In Second At Command Prompt?

By default, the Linux ls command does not show file timestamp with detail of second. If this information is required, you can extend or tweak the ls command capability using option switch.

Otherwise, the stat command can also be used to get or retrieve all file timestamp information (i.e. access, change, and modify time) at one go. Best of all, stat command can display file timestamp in total seconds since Unix Epoch.

Tweaking ls command

There are a number of ls command option switches to deal with timestamp:
  1. ls --full-time is easier to remember, perhaps easiest for novice.
  2. ls -l --time-style="+%d-%m-%Y %H:%M:%S.%N" /proc/net is bit messy but fairly flexible to customize timestamp at wish. The time-style format is identical to convention used by GNU date command.
Most of the file timestamp shows zero for nano second portion. If you’re look at those files in /proc filesystem, e.g. /proc/net, the chance to get significant figure for nano second is higher.

Using stat command

The stat command is part of GNU Core Utilities suite (Coreutils) found in most Linux distributions, e.g. RedHat Linux, used to display file or file system status.

The stat command syntax is easier than ls command, if you simply want to retrieve all file timestamp details in its output:
[root ~] stat /etc/hosts
  File: `/etc/hosts'
  Size: 285      Blocks: 8      IO Block: 4096   regular file
Device: fd00h/64768d    Inode: 24479872    Links: 1
Access: (0644/-rw-r--r--)  Uid: ( 0/ root)   Gid: ( 0/ root)
Access: 2010-12-23 04:02:55.000000000 +0000
Modify: 2010-05-17 17:00:06.000000000 +0100
Change: 2010-05-17 17:00:06.000000000 +0000

For advanced listing, says for example get stat command to display file change timestamp in total number of seconds since Unix Epoch:
[root ~] stat -c%Z /etc/hosts
[root ~] stat --format='%Z seconds since Epoch' /etc/hosts
1274086806 seconds since Epoch
[root ~] stat --format='%Z or %z' /etc/hosts
1274086806 or 2010-05-17 17:00:06.000000000 +0000

Besides the file change timestamp, there are options for displaying file access and modification timestamp. For more information, just run man stat to read the manual page.

Custom Search

2017  •  Privacy Policy