Linux find last modified files

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

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

Читайте также:  Эмулятор ps1 для линукс

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 Find Recent or Today’s Modified Files in Linux

In this article, we will explain two, simple command line tips that enable you to only list all today’s files.

One of the common problems Linux users encounter on the command line is locating files with a particular name, it can be much easier when you actually know the filename.

However, assuming that you have forgotten the name of a file that you created (in your home folder which contains hundreds of files) at an earlier time during the day and yet you need to use urgently.

Below are different ways of only listing all files that you created or modified (directly or indirectly) today.

1. Using the ls command, you can only list today’s files in your home folder as follows, where:

  1. -a – list all files including hidden files
  2. -l – enables long listing format
  3. —time-style=FORMAT – shows time in the specified FORMAT
  4. +%D – show/use date in %m/%d/%y format

Find Recent Files in Linux

In addition, you can sort the resultant list alphabetically by including the -X flag:

You can also list based on size (largest first) using the -S flag:

2. Again, it is possible to use the find command which is practically more flexible and offers plenty of options than ls, for the same purpose as below.

  1. -maxdepth level is used to specify the level (in terms of sub-directories) below the starting point (current directory in this case) to which the search operation will be carried out.
  2. -newerXY , this works if timestamp X of the file in question is newer than timestamp Y of the file reference. X and Y represent any of the letters below:
    1. a – access time of the file reference
    2. B – birth time of the file reference
    3. c – inode status change time of reference
    4. m – modification time of the file reference
    5. t – reference is interpreted directly as a time

This means that, only files modified on 2016-12-06 will be considered:

Find Today’s Files in Linux

Important: Use the correct date format as reference in the find command above, once you use a wrong format, you will get an error as the one below:

Alternatively, use the correct formats below:

Find Todays Modified Files in Linux

You can get more usage information for ls and find commands in our following series of articles on same.

In this article, we explained two important tips of how to list only today’s files with the help of ls and find commands. Make use of the feedback form below to send us any question(s) or comments about the topic. You can as well inform us of any commands used for the same goal.

If You Appreciate What We Do Here On TecMint, You Should Consider:

TecMint is the fastest growing and most trusted community site for any kind of Linux Articles, Guides and Books on the web. Millions of people visit TecMint! to search or browse the thousands of published articles available FREELY to all.

If you like what you are reading, please consider buying us a coffee ( or 2 ) as a token of appreciation.

We are thankful for your never ending support.

Источник

How To Find Files Modified In The Last N Days Or Minutes Using find

This article explains how to find all files in a directory that have been changed in the last N minutes or days, or those with a modification date older than N minutes or days, with examples. This is done using the find command.

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

To find the files that have been changed (with the files data modification time older than) in the last N days from a directory and subdirectories, use:

  • find is the Unix command line tool for finding files (and more)
  • /directory/path/ is the directory path where to look for files that have been modified. Replace it with the path of the directory where you want to look for files that have been modified in the last N days
  • -mtime -N is used to match files that had their data modified in the last N days. Replace N with a number (integer)
  • -ls lists the resulting files (the files that have been modified in the last N days) in ls -dils format on standard output. You can skip this, but using it you’ll get more information like the file size, permissions, the modification date, etc.
  • Find all files modified in the last day (24 hours; between now and a day ago) in a directory and subdirectories:

-mtime -1 is the same as -mtime 0 .

  • Find all files modified in the last 30 days:

But what if you need to find the files that have a modification date older than N , for example older than 30 days? In that case you need to use +N instead of -N , like this:

  • Find all files with a modification date older than 7 days:
  • Find all files modified more than 48 hours ago (at least 2 days ago):
  • Find all files modified between 24 and 48 hours ago (between 1 and 2 days ago):

So why is 1 one day ago, and +1 older than 2 days / 48 hours ago? That’s because according to the man find , any fractional parts are ignored, so if a file was last modified 1 day and 23 hours ago, -mtime +1 won’t match it, treating it as if the file was last modified 1 day, 0 hours, 0 minutes, and 0 seconds ago; see this explanation on why that’s the case

This being the case, how can you get all files modified at least 1 day ago? Use +0 :

Using minutes instead of days

To find the files that have been modified N minutes ago, or with a modification date older than N , simply replace -mtime with -mmin .

So if you want to find the files that have been changed (with the files data modification time older than) in the last N minutes from a directory and subdirectories, use:

  • Find all files modified in the last 5 minutes in a directory and subdirectories:
  • Find all files with a modification date older than 5 minutes:

Источник

How To Find Files Modified in Last 30 Days in Linux

find is the Unix/Linux command line utility used for searching files across the file system. Sometimes we need to search files modified in last few days. Assume you have modified multiple files in your application and forgot to keep track of the modified files. In that case, find command provides you an option to search files based on their modification. You can also search the files modified before X days.

Use -mtime option with the find command to search files based on modification time followed by the number of days. Number of days can be used in two formats.

  1. Use + with number of days to search file modified older that X days
  2. Use with number of days to search file modified in last X days

The below examples will help you to understand the search for files based on modification time.

Find files modified in last X days

Use below command to search all files and directories modified in last 30 days. Here dot (.) is used to search in current directory. And -30 defines to search files modified in last 30 day. Change this number with your search requirements.

You can also customize search based on file type. Use -type followed with -f (file) or -d (directory). Below command will search for files only.

Find files modified before X days

The below command will search all files and directories modified before 30 days. Here dot (.) is used to search in current directory. And +30 defines to search files modified before 30 day. Change this number with your search preferences.

Customize search pattern to search for files only using -type f . Or use -type d to search for directories.

Conclusion

This tutorial described you to find files based on modification days. You can also use more options with find command to filter more.

Читайте также:  Не включается компьютер восстановление запуска windows

Источник

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:

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.

Источник

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