🐧 How to find out the date the file was last modified on Linux

Sometimes you may want to check the details of a file (timestamp), such as the date it was last modified.

This can come in handy when you want to check when this file was last edited.

It also ensures that you have the latest version of the file installed.

🐧 How to determine when the Linux operating system was booted

In this article, you will learn 4 ways to find out the last modified date of a file in Linux.

1. Using stat command

The ls -l command gives you basic information about a file, such as file ownership and permissions, file size and creation date.

The stat command returns the attributes of a file with detailed information, such as when the file was last opened and modified.

The syntax is pretty straightforward.

Stat is followed by the filename or full path to that file.

$ stat filename

🐧 How to find out the date the file was last modified on Linux

From the above output, we can clearly see when the file was last accessed (Access Date), Modified Date, Modified Date of other parameters.

If you want to view only the modified date and omit all other information, run the following command:

$ stat -c ‘%y’ file1.txt

🐧 How to find out the date the file was last modified on Linux

The -c option is used to return the date in a custom format, and the “% y” flag displays the time it was last modified. For catalogs, the syntax remains the same. Just replace the filename with the directory name.

2. Using the date command

The date command displays the current date in the main syntax.

However, when used with the -r option, you can display the last modified date of the file as follows:

$ date -r filename

for instance

$ date -r file1.txt

🐧 How to find out the date the file was last modified on Linux

3. Using the ls -l command

The ls -l command is commonly used to display additional information about files, such as file ownership and permissions, size and creation date.

To list and display the last modified time, use the lt parameter as shown below.

$ ls -lt filename

4. Using httpie

Another way to check the last modified date is to use the httpie command line client tool.

HTTPie is a modern HTTP client similar to Curl and Wget commands

The tool is commonly used to interact with HTTP servers and APIs, and can also check when a file residing on a web server was last modified.

But first you need to install it using the command:

$ pip3 install httpie --user

Ubuntu / Debian / Mint:

$ sudo apt install httpie

To check when a file was last modified on the web server, use the syntax:

$ http -h  [url] | grep 'Last-Modified'

For instance:

$ http -h https://itsecforu.ru/wp-content/uploads/2020/09/Fedora.png | grep -i 'Last-Modified'

Output:

Last-Modified: Fri, 18 Sep 2020 22:38:48 GMT

Conclusion

This concludes the article.

In this tutorial, we have described various ways in which you can find out the last modified date of a file on a Linux system, and even a file hosted on a web server, using the httpie tool.

I hope you won’t have any problems viewing the last modified time of the files.

Sidebar