How to View Linux File Timestamps? [3 Easy Methods]

Written by

Reviewed by

Last updated: July 11, 2024

Expert verified

SVG Image

TL;DR

To see the Linux file timestamps, try any of the following three methods:

  1. Use ls -l to view file modification times and ls --time=atime or ls --time=ctime for access and change times, offering a quick way to track file changes directly from the terminal.
  2. Execute stat [file_name] to get a detailed report on file statistics including all timestamps (access, modification, change times), providing a precise look at file metadata.
  3. Access file timestamps via GUI file managers like Nautilus (GNOME), where you can customize views to include columns for Date Modified, Date Accessed, and Changed, facilitating an intuitive and visual approach to file metadata management.

Continue reading the guide below to learn three different methods to see the Linux file timestamps. Also, learn about the types of timestamps, how to change the timestamps of a file, and some tips for managing timestamps in Linux.

Ever wondered when a file on your Linux system was last modified or accessed? Whether you’re a developer keeping track of changes, a system administrator protecting server integrity, or just curious about your files, knowing how to manage timestamps is key. Luckily, Linux offers some great tools to help you out.

In this article, I’ll walk you through various methods to view and manage file timestamps. I’ll cover everything from simple command-line utilities like ls and stat to more user-friendly graphical interfaces in file managers like Nautilus. Let’s get started!

What are the Three Types of Linux File Timestamps?

Linux file systems track three key timestamps for each file and directory: Access Time (atime), Modification Time (mtime), and Change Time (ctime). These timestamps provide valuable insights into when a file was last read, edited, or had its metadata altered, playing a critical role in file management and security monitoring.

  1. Access Time (atime): This timestamp indicates the last time the file was accessed or read by a process. For example, when a file is read by a text editor or a command like cat.
  2. Modification Time (mtime): This timestamp shows the last time the file’s content was modified. If you edit a file and save changes, the modification time will be updated to reflect the time of those changes.
  3. Change Time (ctime): Often confused with mtime, the change time represents the last time the file’s metadata or inode information was changed. Changes to metadata could include modifications to file permissions, ownership, or moving the file to a different location in the filesystem. Importantly, ctime is also updated when the file’s content is modified, just like mtime.

How to View Linux File Timestamps?

To view Linux file timestamps, you can use the stat command for detailed information, including Access Time (atime), Modification Time (mtime), and Change Time (ctime). Alternatively, the ls -l command displays the modification time directly in the Terminal. For a graphical approach, you can check timestamps using GUI file managers like Nautilus, where you can right-click on a file and select ‘Properties’ to see the timestamps.

Here is the step-by-step guide to use each method:

1. ls Command

The ls command in Linux is a fundamental tool used to list directory contents and display information about files and directories. Among other details, ls can show file modification times by default, which is crucial for users to track changes. Follow these steps to view file timestamps in Linux using ls command:

  1. Open your terminal.
open terminal
  1. To view the modification times of files, type: 
ls -l

This command will display a detailed list including the file size, modification time, and filename.

viewing detailed info about file
  1. For access times (atime), use the command: 
ls --time=atime -l

This command will show the access times of the files.

viewing access time of files
  1. For change times (ctime), use the command:
ls --time=ctime -l

It will show the change times of the files.

viewing change time of files

2. stat Command

The stat command provides detailed information about the file system status for files or filesystems. It’s particularly useful for obtaining precise data on timestamps, including access, modification, and change times. Here is how to use this command to see file timestamps in Linux:

  1. Access your command window and run the following command:
stat [file_name]

Replace [file_name] with the name of your file, then press Enter.

  1. This output shows the exact times for each type of timestamp, providing clear insights into when the file was accessed, modified, and changed.
viewing timestamps using stat command

3. Graphical User Interface (GUI) Methods

Modern GUI file managers like Nautilus (GNOME) is equipped with the capability to display file timestamps, providing a user-friendly way to access file metadata. For a detailed step-by-step guide to installing GNOME on a Linux system, read this guide. Here is how to do it:

  1. Open Nautilus from the application menu.
opening nautilus file explorer
  1. Right-click on the file and click on properties.
opening properties of a file
  1. Check Date Modified, Date Accessed, and any other timestamp-related columns.
viewing timestamps of a file using GUI

How to Change File Timestamps in Linux?

Linux offers the flexibility to adjust these timestamps using the touch command. This command not only allows you to create new empty files but also to modify the timestamps of existing files. Here is how to change file timestamps in Linux:

  1. Begin by opening your Terminal.
  2. Execute the stat command to show the current timestamps of the file.
stat filename

It will display the file’s detailed information, including its current timestamps. Replace the filename with the actual filename.

viewing current timestamps of a file
  1. Now update both access and modification times by running the command:
touch filename

This command will update both the access and modification times of the specified file to the current system time. Again verify the modification using stat command. Replace the filename with the actual filename.

changing timestamps to current time
  1. To set specific timestamps of a file use the following command:
touch -t 202305071230.00 filename

This command sets the access and modification times of the filename to May 7, 2023, at 12:30:00. Verify the change using the stat command. Replace the filename with the actual filename.

changing timestamps to a specific time
  1. To modify only the modification time:
touch -m -t 202308081130.00 filename

Using this command will change only the modification time of the file to the specified date and time, leaving the access time unchanged. Replace the filename with the actual filename.

changing only the modification time of the file
  1. To modify only the access time
touch -a -t 202309091330.00 filename

This command adjusts only the access time to the specified moment without altering the modification time. Replace the filename with the actual filename.

changing only the access time of the file
  1. If you need to duplicate the timestamps from one file to another, you can use the following command:
touch -r referencefile targetfile

This will set the access and modification times of targetfile to be the same as those of referencefile.

copying another file timestamps

6 Tips for Managing Timestamps in Linux

Mastering timestamps in Linux is key to effective file management. Whether you’re a system administrator or a regular user, understanding how to handle timestamps can greatly enhance your workflow. Here are six enhanced tips to help you manage file timestamps more effectively.

  • 🕒 Check Timezone Settings: Make sure your Linux system’s timezone is set correctly to avoid timestamp errors. This is particularly important when working with servers or databases across different time zones, which can lead to misinterpretations of file modification times.
  • 🔄 Update System Clock Regularly: Regularly synchronize your computer’s clock with an online time server using the Network Time Protocol (NTP). This ensures your file timestamps are always accurate, avoiding issues in time-sensitive applications like scheduling and log management.
  • 🧐 Use ISO Format for Clarity: Always format timestamps using the ISO 8601 standard (YYYY-MM-DD HH:MM:SS) in your scripts and documentation. This format avoids confusion between US and international date formats and is easy to sort chronologically in listings.
  • 🛠️ Modify Timestamps with touch: If you need to update or reset a file’s timestamps, use the touch command. This can help simulate file usage or modifications during testing or when restoring files after a data recovery process.
  • 📊 Compare Timestamps with find: Utilize the find command to search for files by their timestamps. For example, to find files modified within the past week, use find /path/to/search -mtime -7. This is useful for auditing and cleanup operations.
  • 💾 Backup Timestamps: When backing up files, ensure your backup solution supports preserving timestamps. Tools like rsync are ideal as they can replicate files exactly, including their timestamps, which is crucial for restoring a system to a previous state accurately.

In a Nutshell

In this article, I’ve covered various methods to view Linux file timestamps, using command-line tools like ls, stat, and GUI methods through file managers like Nautilus. I’ve also shared several practical tips to help you manage these timestamps more effectively, aiming to streamline your file management tasks.

For more learning, you might want to look into sorting files by date and time, which helps you organize files easily. Learning more about the stat command can give you deeper insights into file details, and getting good with the find command can make searching files by their timestamps quicker and more efficient. These topics build on what we’ve covered and can really improve your skills in Linux.

Frequently Asked Questions

How can I preserve timestamps while copying files in Linux?

To preserve timestamps while copying files in Linux, use the cp command with the -p (preserve) option. This command preserves the modification and access times along with the file’s permissions and ownership, ensuring that the copied file retains its original metadata.

Is there a way to modify timestamps for a file without altering its contents?

Yes, you can modify the timestamps of a file without changing its contents by using the touch command. With options like -a for access time and -m for modification time, you can update either or both timestamps as needed, leaving the file contents unchanged.

Can I restore original timestamps after modifying a file?

If you’ve modified a file and need to restore its original timestamps, you can use the touch -r command. This command allows you to reference another file’s timestamps or manually set them if previously noted, effectively restoring the original date and time metadata.

What command shows the oldest files in a directory based on timestamps?

To find the oldest files in a directory based on their modification timestamps, use the ls -ltr command. This command lists files in reverse chronological order, placing the oldest files at the bottom of the output, making it easier to identify the files that were modified first.

Ojash

Author

Ojash is a skilled Linux expert and tech writer with over a decade of experience. He has extensive knowledge of Linux's file system, command-line interface, and software installations. Ojash is also an expert in shell scripting and automation, with experience in Bash, Python, and Perl. He has published numerous articles on Linux in various online publications, making him a valuable resource for both seasoned Linux users and beginners. Ojash is also an active member of the Linux community and participates in Linux forums.

Akshat

Reviewer

Akshat is a software engineer, product designer and the co-founder of Scrutify. He's an experienced Linux professional and the senior editor of this blog. He is also an open-source contributor to many projects on Github and has written several technical guides on Linux. Apart from that, he’s also actively sharing his ideas and tutorials on Medium and Attirer. As the editor of this blog, Akshat brings his wealth of knowledge and experience to provide readers with valuable insights and advice on a wide range of Linux-related topics.

Share this article
Shareable URL
Prev Post

How to Get All Keys in Redis Using Command Line Interface? [2 Best Methods]

Next Post

4 Effective Ways to Delete Multiple Keys in Redis CLI

Leave a Reply

Your email address will not be published. Required fields are marked *

Read next