How to display access time of files and directories using the ls command in Linux?

Published on Aug. 22, 2023, 12:17 p.m.

To display the access time of files and directories using the ls command in Linux, you can use the -u option. This option tells ls to use the access time (atime) instead of the modification time (mtime) for sorting and displaying files. Here is an example command that displays the access time of all files and directories in the current directory:

ls -lu

This command will list all files and directories in the current directory, with the access time displayed in the format yyyy-mm-dd hh:mm:ss.

Note that the -u option only affects the sorting and display of files and directories, not their actual atime values. By default, Linux systems use the relatime mount option for file systems, which updates the atime value only if it is older than the mtime or ctime values. This reduces unnecessary disk writes and can improve overall system performance. If you need to maintain accurate atime values, you can use the noatime mount option, but this will result in increased disk activity and may affect system performance.

Tags:

ls