Linux find files time

How do I find all the files that were created today in Unix/Linux?

On my Fedora 10 system, with findutils-4.4.0-1.fc10.i386 :

find -daystart -ctime 0 -print 

The -daystart flag tells it to calculate from the start of today instead of from 24 hours ago.

Note however that this will actually list files created or modified in the last day. find has no options that look at the true creation date of the file.

That is almost perfect for me, clean and concise, just missing the «-f» flag to get only files (without current dir)

(@ephemient: Well, with *nix, the ctime of an inode was colloquially known as the creation time, even if the specification said (inode) change time (keeping neither changes to file names nor contents, but meta data like ownership, permissions,…. sleuthkit on «MAC» meaning))

find . -mtime -1 -type f -print 

Don’t use backticks; don’t use pwd except for printing (that’s the p in pwd ) the working directory. Use . to reference current directory.

this answer is incorrect — this displays the files created in the last 24 hours, not the files created today

@G.Lebret -ctime is the time the file’s status was last changed. Unix doesn’t store file creation time, last modified time is obviously equivalent to creation time if nothing modified the file after it was created.

To find all files that are modified today only (since start of day only, i.e. 12 am), in current directory and its sub-directories:

touch -t `date +%m%d0000` /tmp/$$ find . -type f -newer /tmp/$$ rm /tmp/$$ 

I use this with some frequency:

$ ls -altrh --time-style=+%D | grep $(date +%D) 

After going through many posts I found the best one that really works

find $file_path -type f -name "*.txt" -mtime -1 -printf "%f\n" 

This prints only the file name like abc.txt not the /path/tofolder/abc.txt

Also also play around or customize with -mtime -1

This worked for me. Lists the files created on May 30 in the current directory.

Use ls or find to have all the files that were created today.

Using ls : ls -ltr | grep «$(date ‘+%b %e’)»

Читайте также:  Linux run file as root

Using find : cd $YOUR_DIRECTORY ; find . -ls 2>/dev/null| grep «$(date ‘+%b %e’)»

 find ./ -maxdepth 1 -type f -execdir basename '<>' ';' | grep `date +'%Y%m%d'` 

Welcome to Stack Overflow. Code dumps without any explanation are rarely helpful. Stack Overflow is about learning, not providing snippets to blindly copy and paste. Please edit your question and explain how it answers the specific question being asked. See How to Answer. This is especially important when answering old questions (this one is over 12 years old) with existing answers.

You can use find and ls to accomplish with this:

find . -type f -exec ls -l <> \; | egrep "Aug 26"; 

It will find all files in this directory, display useful informations ( -l ) and filter the lines with some date you want. It may be a little bit slow, but still useful in some cases.

Источник

How to Find Files Based on Timestamp in Linux

The find command in Linux is used to search for files and folders based on different parameters. These parameters can be the filename, size, type of file, etc.

One such parameter is the timestamp of the file. In Linux (and all Unix based file systems) there are 3 timestamps maintained for every file:

  1. Last Modification Time
  2. Last Access Time
  3. Last Status Change Time (i.e., when metadata of the file like permissions are changed)

Let’s see how to use find to search for files based on each of these timestamps.

Find File Timestamps in Linux

First of all, we can run the ‘stat‘ command in Linux to get all these timestamps for a file. For example for a file with the name ‘stat‘, run:

Find Stat Timestamps

Find Files Based on Timestamp

Now, to find files based on the timestamp, we use the argument ‘-newerXY’ of find from the man page.

Man Page of Find Command

Thus in the argument ‘-newerXY’ , we can have X as a, c, or m, respectively for last access, last status change, and last modification times, and Y as t, so that we can have the next argument to be a timestamp string.

Note: The birth time, i.e. creation time of a file is not maintained in Unix based file systems

To generalize, the command to be run looks like this:

Here, the format of the timestamp should be: ‘YYYY-MM-DD HH:MM:SS’.

Let’s try this on a folder with few files and only two files having accessed, modified and status changed after a specified time.

find . -newerat ‘2021-02-19 06:34’ find . -newerct ‘2021-02-19 06:34’ find . -newermt ‘2021-02-19 06:34’

Find Files Based on Timestamp

Verify with ‘stat’ if the timestamps of both files are indeed greater than the specified time.

Читайте также:  Adapter linux usb wireless lan

Verify File Timestamp

Conclusion

We have learned how to use the ‘-newerXY’ the argument of command find to search for files based on timestamp.

Note that you can also use another file for a reference timestamp instead of explicitly specifying the timestamp, in which case the ‘t’ from the argument can be skipped.

Thanks a lot for reading and let us know your thoughts in the comments below!

Источник

Find files in created between a date range

If you use GNU find , since version 4.3.3 you can do:

find -newerct "1 Aug 2013" ! -newerct "1 Sep 2013" -ls 

It will accept any date string accepted by GNU date -d .

You can change the c in -newerct to any of a , B , c , or m for looking at atime/birth/ctime/mtime.

Another example — list files modified between 17:30 and 22:00 on Nov 6 2017:

find -newermt "2017-11-06 17:30:00" ! -newermt "2017-11-06 22:00:00" -ls 

Full details from man find :

 -newerXY reference Compares the timestamp of the current file with reference. The reference argument is normally the name of a file (and one of its timestamps is used for the comparison) but it may also be a string describing an absolute time. X and Y are placeholders for other letters, and these letters select which time belonging to how reference is used for the comparison. a The access time of the file reference B The birth time of the file reference c The inode status change time of reference m The modification time of the file reference t reference is interpreted directly as a time Some combinations are invalid; for example, it is invalid for X to be t. Some combinations are not implemented on all systems; for example B is not supported on all systems. If an invalid or unsupported combination of XY is specified, a fatal error results. Time specifications are interpreted as for the argument to the -d option of GNU date. If you try to use the birth time of a reference file, and the birth time cannot be determined, a fatal error message results. If you specify a test which refers to the birth time of files being examined, this test will fail for any files where the birth time is unknown. 

Источник

How to display modified date time with ‘find’ command?

With a find command, I can display directories names with multiple levels. The following command display all directories under /var path with a depth of 2:

find /var -maxdepth 2 -type d; 
/var /var/log /var/log/sssd /var/log/samba /var/log/audit /var/log/ConsoleKit /var/log/gdm /var/log/sa 
stat /var/log/samba | grep 'Modify:' 
Modify: 2014-01-02 11:21:27.762346214 -0800 

Is there a way to combine the two commands so that directories will be listed with modified date time?

Читайте также:  Линукс изменить владельца файла

6 Answers 6

The accepted answer works but it’s slow. There’s no need to exec stat for each directory, find provides the modification date and you can just print it out directly. Here’s an equivalent command that’s considerably faster:

 find /var -maxdepth 2 -type d -printf "%p %TY-%Tm-%Td %TH:%TM:%TS %Tz\n" 

A much better solution. It also works with the find from msys running on Windows, which lacks a stat command.

More helpful links for explanation of % formatters. unix.stackexchange.com/a/215236/216480 or on the man page search for «-printf format»

While the format string «%p %Tc» does work, it formats the output slightly differently. E.g. «/var/spool Mon 29 Sep 2014 09:05:54 BST» instead of «/var/spool 2014-09-29 09:05:54.000000000 +0100».

You could use the -exec switch for find and define the output format of stat using the -c switch as follows:

find /var -maxdepth 2 -type d -exec stat -c «%n %y» <> \;

This should give the filename followed by its modification time on the same line of the output.

The -printf option below avoids calling stat for every file found. In my test the command yields almost identical output, just an extra digit’s precision on the seconds.

For MacOS the format arg character for stat is -f . find /var -maxdepth 2 -type d -exec stat -f «%t%Sm %N» <> \;

Recent GNU versions of find also include a -printf option which includes date fields. If you need to print the file’s name and modification time in the standard «C» format, you can use -printf «%c %p\n» .

If you want the date in a specific format, you can use the %C followed by a field character. For example, 4-digit year would be %CY , with Y being the character for 4-digit year.
Note that if you need multiple fields, you’ll need to specify %C multiple times. For example, YYYY-MM-DD format would look like %CY-%Cm-%Cd .

Check the man pages or online documentation for additional details.

Here is a working example:

find . -name favicon.ico -printf "%c %p\n" 

Источник

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