27 C
Jaipur
Thursday, October 29, 2020

How to Get Last Modified Date of File in Linux

Must read

UbuntuDDE Remix 20.10 Released With Linux 5.8, Snap Plugin, And More

Earlier this year, we reported about a brand new UbuntuDDE Remix that combines the power of Ubuntu Linux and Deepin Desktop Environment (DDE) from...

How to Use apt-cache Command in Linux

With apt-cache command, you can search for package details in the local APT cache. Learn to use apt-cache command in this tutorial. What is apt-cache...

AMD Releases Its RX 6000 Series of GPU to Take on Nvidia

AMD yesterday finally unveiled its brand new GPUs — the much awaited Big Navi announcement with the RX 6000 series of graphics cards. The...

Flipkart quiz October 29, 2020: Answer these five questions to win gifts, coupons and Flipkart Super coins

Flipkart quiz is live on Flipkart mobile app. For the unknown, the quiz starts daily at 12am and runs till 12pm. The quiz...

Sometimes, you may be required to check detailed information about a file (timestamp) such as its last modified date. This can come in handy when you want to check when the file was last edited. Additionally, it ensures that you have the latest version of the file.

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

1. Using stat command

The ls -l  command is just okay in giving you basic information about a file such as file ownership and permissions, file size, and creation date. The stat command returns detailed information file attributes such as the last time the file was accessed and modified.

The syntax is quite simple. stat is followed by the file name or the full path to the file.

$ stat filename
stat command

stat of ‘file1.txt’

From the above output, we can clearly see when the file was last accessed ( Access date ),  Modify date,  Change date among other parameters.

If you wish to view the modified date only and leave out all the other information, run the following command:

$ stat -c ‘%y’ file1.txt
Use stat command to only check modified date

Use stat command to only check modified date

The -c option is used to return the date in a custom format, while the '%y' flag displays the last modification time. For directories, the syntax remains the same. Simply replace the file name with that of the directory.

2. Using date command

The date command in its basic syntax displays the current date. However, when used with the -r option, you can display the last modification date of a file as shown.

$ date -r filename

For example,

$ date -r file1.txt
date command to display last modified date

date command to display last modified date

3. Using ls -l command

The ls -l command is usually used for long listing – display additional information about a file such as file ownership and permissions, size and creation date. To list and display the last modified times, use the lt option as shown.

$ ls -lt filename
check last modified file uing ls -lt

check last modified file uing ls -lt

4. Using httpie

Another way you can check the last modified date is by using the httpie HTTP command-line client tool. The tool is usually used for interacting 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

On Ubuntu / Debian / Mint, run the command:

$ sudo apt install httpie

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

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

For example:

$ http -h https://linoxide.com/wp-content/uploads/2020/09/Fedora-32-desktop.png | grep -i 'Last-Modified'

Output

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

Conclusion

This wraps up this article. In this guide, we have featured various ways that you can use to list the last modified date of a file on a Linux system, and even a file hosted on a web server using the httpie tool. Hopefully, you won’t have an issue viewing when files were last modified.

Source link

- Advertisement -

More articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest article

UbuntuDDE Remix 20.10 Released With Linux 5.8, Snap Plugin, And More

Earlier this year, we reported about a brand new UbuntuDDE Remix that combines the power of Ubuntu Linux and Deepin Desktop Environment (DDE) from...

How to Use apt-cache Command in Linux

With apt-cache command, you can search for package details in the local APT cache. Learn to use apt-cache command in this tutorial. What is apt-cache...

AMD Releases Its RX 6000 Series of GPU to Take on Nvidia

AMD yesterday finally unveiled its brand new GPUs — the much awaited Big Navi announcement with the RX 6000 series of graphics cards. The...

Flipkart quiz October 29, 2020: Answer these five questions to win gifts, coupons and Flipkart Super coins

Flipkart quiz is live on Flipkart mobile app. For the unknown, the quiz starts daily at 12am and runs till 12pm. The quiz...