Linux show last modified files

Содержание
  1. Linux Find Files Modified in Last Number of Days
  2. Types of file timestamps
  3. Using Mtime — modification time
  4. Using atime — File access
  5. The -daystart option
  6. The -newer option
  7. Conclusion
  8. How to Get Last Modified Date of File in Linux
  9. 1. Using stat command
  10. 2. Using date command
  11. 3. Using ls -l command
  12. 4. Using httpie
  13. Output
  14. Conclusion
  15. More Articles You May Like
  16. 1 thought on “How to Get Last Modified Date of File in Linux”. add one
  17. How to find recently modified files in Linux
  18. How to check all timestamps of a file?
  19. 1) Sorting files & folders based on conversion time
  20. 2) Sorting only folders based on conversion time
  21. 3) How to find only files that were modified 120 days ago
  22. 4) How to find only files that were modified in last 15 days
  23. 5) How to find only files that were modified exactly 10 days ago
  24. 6) How to find only files that were modified within last 30 Mins
  25. 7) How to find only the folder’s modified in last 5 Days
  26. 8) How to find both Files and Folders that were modified in last 15 Days
  27. 9) How to find modified files and folders starting from a given Date to the latest Date
  28. 10) How to find all files and folders modified in the Last 24 Hours
  29. 11) How to find a list of “sh” extension files accessed in the Last 30 Days
  30. 12) How to find files that have been modified over a period of time
  31. 13) How to find a list of files created Today
  32. Closing Notes
  33. Get Last Modified Date of File in Linux
  34. Get Last Modified Date of a File in Linux with the command date
  35. Get Last Modified Date of Files in Linux using the ls command
  36. Learn Last Modified Date of a File in Linux using stat
  37. Conclusion
  38. About the author
  39. David Adams

Linux Find Files Modified in Last Number of Days

The Linux find command is a handy tool that lets you find or locate files on your system. You can specify to locate a file based on wide criteria such as file type, file location, and file permissions to mention a few. Additionally, you can find files changed in the last number of days. And this will be the focus of this tutorial and will explore various ways to retrieve files based on their timestamps.

Types of file timestamps

Files in Linux bear the following timestamps:

atime: This is the access timestamp and it reveals the last time a file was read or accessed. This implies an application was used to open the file and read its contents.

amin: This prints out when the file was accessed in minutes.

mtime: This is the modified timestamp. It reveals when a file was last modified either by a program or a user. The mtime changes when the file’s contents are changed or modified. By ‘modify’ we mean that some data was appended to the file, reorganized or deleted partly or wholly.

mmin: The mmin directive reveals the last time a file was modified in minutes.

ctime: This is the change time or change timestamp. It reveals when the file’s properties changed. A good example is modifying file ownership or permissions which effectively changes the timestamp.

That’s a brief overview of the timestamps. Here we will focus more on the ‘atime and ‘mtime‘ timestamps.

Using Mtime — modification time

In this section, we will focus on how you can go about searching for files with timestamps that fall within a certain range using the mtime option. This lists files accessed days ago.

To list files whose timestamp changed in the last 90 days use the + mtime 90 option.

  1. — mtime+90 Implies that you are looking for a file changed more than 90 days ago.
  2. — mtime -90 Means that you are looking for a file changed less than 90 days ago.
  3. -mtime 90 Means you are looking for a file modified exactly 90 days.

For example, to search for txt files in the /home/james/data directory that were modified less than 90 days ago use the following command:

Additionally, you can use numerical parameters as shown:

  • — 1 the last 24 hours
  • — 0.5 the last 12 hours
  • — 0.25 the last 6 hours
  • +2 more than two days

For example, the following command displays text files modified in the last 12 hours

Читайте также:  Перенос локального профиля пользователя windows 10

Using atime — File access

As we have seen previously, atime is the attribute used for showing the last time a file was accessed by a user or an application. Let’s check out a few examples:

To view all text files in the home directory accessed within the last 30 days, run

To view the docx files accessed precisely 20 days ago, run the command below. Note that there’s no minus sign before the 20 value.

The -daystart option

The -daystart option measures the time from the start of the current day instead of 24 hours ago. For example. to find out all pdf files edited yesterday, run:

To list the files edited between 3-5 days ago, run the command:

The -newer option

The -newer option compares files from two different directories and displays the files that are newer. For example, to find files that are newer in the /home/james/Downloads directory than in the /home/james/images directory, run the following command

Conclusion

This concludes our topic today where we looked at how to list files changed in the last number of days or accessed within a certain time duration. To get the last modified date of file you can use a few different commands in Linux.

Источник

How to Get Last Modified Date of File in Linux

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.

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:

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.

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.

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:

On Ubuntu / Debian / Mint, run the command:

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

Output

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.

1 thought on “How to Get Last Modified Date of File in Linux”. add one

I prefer using ‘ls’ over all the others because ls allows you to control precisely how the date and time are displayed. I believe stat only gives the choice between seconds-since-epoch and human-readable, with no control over the human-readable format.

For ls, the relevant option is ‘—time-style’ and its format specifiers are fairly straightforward, using the same specifiers used by /bin/date. See ‘man date’ for all the available specifiers. My personal favorite is —time-style=»+%Y-%m-%d %H:%M:%S». I use this alias for my day-to-day ls needs.

Читайте также:  Windows 10 восстановление системы при загрузке не удалось восстановить компьютер

alias l=»/bin/ls —time-style=\»+%Y-%m-%d %H:%M:%S\» —group-directories-first -lLFAGv»

Источник

How to find recently modified files in Linux

If you are working on thousands of files a day and want to find a list of files that have been modified recently in a directory for certain purposes, this can be done easily using the find command.

The find command is used to search or locate files based on various criteria such as timestamp, file type and file permissions in Linux.

Please refer to our previous article on how to find a directory size in Linux.

In this article, we have included 13 examples for locating files based on timestamp and I hope this article will meet your needs.

In Linux, a file contains three timestamps, which are updated when a file is accessed or modified or replaced.

Types of file timestamps:

  • atime: access time or Last access time
  • mtime: modify time or Last modification time
  • ctime: change time or Last change time

Read the below explanation for better understanding about timestamp.

  • atime/amin: The last time the file was accessed by some command or application.
  • mtime/mmin: The last time the file’s contents was modified.
  • ctime/cmin: The last time the file’s attribute was modified.

How to check all timestamps of a file?

It can be easily seen using ‘stat’ command, which displays all three timestamps of a file.

The common syntax is as follows:

We can use numerical arguments with ‘mtime’. Use “-mtime n” command to return a list of files that were last modified “n” hours ago.

  • +n: for greater than n
  • -n: for less than n
  • n: for exactly n

See the format below for a better understanding.

  • -mtime +10: This will find all files that were modified 10 days ago.
  • -mtime -10: It will find all files that were modified in the last 10 days.
  • -mtime 10: Use this format to find all files that were modified EXACTLY 10 days ago.

1) Sorting files & folders based on conversion time

This can be done by using the ls command with some options as shown below, which sorts the files and folders in reverse order based on the conversion time.

2) Sorting only folders based on conversion time

Use the following format to sort only folders in reverse order based on conversion time.

3) How to find only files that were modified 120 days ago

The below find command will show a list of files that were changed 120 days ago.

4) How to find only files that were modified in last 15 days

The below find command will show a list of files that have changed in the last 15 days:

5) How to find only files that were modified exactly 10 days ago

The below find command will show you a list of files that were changed exactly 10 days ago:

6) How to find only files that were modified within last 30 Mins

The below find command will show a list of files that have changed within the last 30 mins.

7) How to find only the folder’s modified in last 5 Days

This command displays only folders modified within the last 5 days.

8) How to find both Files and Folders that were modified in last 15 Days

This command displays a list of files and folders modified within last 15 days:

9) How to find modified files and folders starting from a given Date to the latest Date

This command allows you to find a list of files and folders that have been modified starting from a given date to the latest date:

10) How to find all files and folders modified in the Last 24 Hours

Alternatively, you can use an easy-to-understand format like the one below to find files and folders that have changed over the past 24 hours.

11) How to find a list of “sh” extension files accessed in the Last 30 Days

This command helps you to find a list of files with “sh” extension accessed in the last 30 days.

12) How to find files that have been modified over a period of time

The below command shows a list of files that have changed in the last 20 minutes.

13) How to find a list of files created Today

This command enables you to find a list of files created today:

Читайте также:  Linux mint как записать загрузочную флешку

Closing Notes

This article explained how to find recently modified files & folders in Linux.

If you have any questions or feedback, feel free to comment below.

Источник

Get Last Modified Date of File in Linux

Get Last Modified Date of a File in Linux with the command date

The first method to learn the last modification date of a file in Linux explained in this tutorial focuses on the date command. When the command date is followed by the -r flag, it shows us the last modification date of a file.

The following example shows the syntax to use the date command, where linuxhint is the file whose last modification date I want to be printed.

As you can see, the output is very user-friendly and includes the date and time of the last modification done on the file.

Get Last Modified Date of Files in Linux using the ls command

The second method explained in this tutorial explains how to get the last modified date of a file using the ls command.

First, let’s use the ls command followed by the -l flag, as shown in the screenshot below. The -l flag instructs the ls command to print a long format list of files. The long format list includes the last modification date of a file.

As you can see, the first column shows the permissions, the second and third column shows file users and groups. The fourth column is the size. Then you can see the month, day, and time in which the file was modified. Contrary to the previous method with ls, you will get a list of all files in the directory, including their modification dates.

For an ordered output, you can add the -t flag. The -t flag will print the output ordered by modification date, showing the last modified files first, as shown in the following image.

As you can see now, the last modified files are now shown first.

The ls command also allows you to check the last modification date of a file individually; for this, just specify the file’s name as shown below.

As you can see, this output is more user-friendly if you only want to check a single file.

You can get additional information on the ls command at its mane page https://en.wikipedia.org/wiki/Ls.

Learn Last Modified Date of a File in Linux using stat

The third method to get the last modification date of a file in Linux explained in this article shows how to use the stat command for this purpose.

The syntax is pretty simple; just run the stat command followed by the file’s name whose last modification date you want to know, as shown in the example below.

As you can see, the output shows more information than previous commands. It is important to differentiate the modification and change dates.

The row named Modify shows us the last time the file was modified. The row named Change shows the last time the status of the file changed; the status includes permissions change, ownership change, etc.

You can run the command below to get in the output only the modification time, omitting the rest of the information.

As you see, the output is limited to the last modification date.

The stat command also allows us to check several files at once, as shown in the example below, in which files named linuxhint, and linuxhintfile are checked.

Now we get information on the two files we specified.

Conclusion

This tutorial shows that getting the last modified date of a file in Linux can be done through different simple methods. There is no special advantage for any of the methods explained; all of them can be implemented easily and without installing additional packages. For this tutorial, I used Debian, but all commands described here are available in all Linux distributions. All the commands explained have additional features you can know by reading the man pages specified at the end of each section.

Thank you for following us; keep reading Linux Hint for additional tips and tutorials.

About the author

David Adams

David Adams is a System Admin and writer that is focused on open source technologies, security software, and computer systems.

Источник

Оцените статью