Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Search based on file timestamps (atime, ctime, mtime) #165

Closed
guihkx opened this issue Nov 11, 2017 · 14 comments
Closed

Search based on file timestamps (atime, ctime, mtime) #165

guihkx opened this issue Nov 11, 2017 · 14 comments

Comments

@guihkx
Copy link

guihkx commented Nov 11, 2017

find has this very useful feature that I use often, which is timestamp-based file search. You're probably familiar with it already, but here's the documentation for those flags:

-atime n
              File  was  last  accessed n*24 hours ago.  When find figures out
              how many 24-hour periods ago the file  was  last  accessed,  any
              fractional part is ignored, so to match -atime +1, a file has to
              have been accessed at least two days ago.

-ctime n
              File's status was last changed n*24 hours ago.  See the comments
              for -atime to understand how rounding affects the interpretation
              of file status change times.

-mtime n
              File's  data was last modified n*24 hours ago.  See the comments
              for -atime to understand how rounding affects the interpretation
              of file modification times.

What do you think? Thank you.

@sharkdp
Copy link
Owner

sharkdp commented Nov 12, 2017

Sounds good. Do we need all three? I would guess that -mtime is used most of the time? Also, not all of them will be available cross-platform.

@guihkx
Copy link
Author

guihkx commented Nov 12, 2017

I just use -mtime as well, but I suggested all of them just in case. 👍

@ChengCat
Copy link

I agree with adding support for only file modification time. And I think a more powerful syntax for describing the time duration may help, e.g. 20min, 1h, 5d. Time moment is helpful too, but that could be too ambiguous.

@sharkdp
Copy link
Owner

sharkdp commented Jan 8, 2018

Just an idea, but I think it would be cool if we could parse relative timespans (as well as absolute date/times) and allow for things like:

fd --older-than "2 weeks"
fd --changed-within "3 days"

Related: https://crates.io/crates/chrono-humanize

@sharkdp sharkdp changed the title (Feature Request) Search based on file timestamps (atime, ctime, mtime) Search based on file timestamps (atime, ctime, mtime) Feb 10, 2018
@Dowwie
Copy link

Dowwie commented Apr 2, 2018

I agree that an mtime feature would be a valuable addition

@Manozco
Copy link

Manozco commented Apr 27, 2018

atime is a nice feature when you want to clean a file server :)
in GNU find, there is also amin, cmin and mmin that that does the same thing as the ?time variants but based on minutes instead of hours, (very) useful when you want smaller granularity :)

@sharkdp
Copy link
Owner

sharkdp commented Oct 1, 2018

Not completely sure about the best names for those options, but I think we should move forward by using humantime::parse_duration to implement both --changed-within and --older-than (or --changed-before?).

@kimsnj
Copy link
Contributor

kimsnj commented Oct 6, 2018

Hi,
I'd be interested in tackling this issue.
Could I have some pointers for starting?

@sharkdp
Copy link
Owner

sharkdp commented Oct 6, 2018

@kimsnj Sounds great.

I think a good way to start would be to look at how similar features are implemented: --extension, --type or --size.

@sharkdp
Copy link
Owner

sharkdp commented Oct 10, 2018

This has been implemented in #339 by @kimsnj (Thanks!!).

If anybody has ideas for the command-line naming "problem" mentioned in the description of #339, please comment here!

@sharkdp sharkdp added this to the v7.2.0 milestone Oct 27, 2018
@sharkdp
Copy link
Owner

sharkdp commented Oct 27, 2018

finally closed in deea31c

@sharkdp sharkdp closed this as completed Oct 27, 2018
@sharkdp
Copy link
Owner

sharkdp commented Oct 27, 2018

Released in fd-7.2.0.

@adRn-s
Copy link

adRn-s commented Mar 8, 2023

For the record, I just went back to relying on find because I need either ctime or atime since I want to clean files that are old, but I want to still preserve files that, for example, were downloaded from a server with an 'old' timestamp that both mtime and fd fail to process as required... Otherwise, I'd be cleaning files that users downloaded yesterday but were put online a few years ago.

@Ultra-Code
Copy link

For the record, I just went back to relying on find because I need either ctime or atime since I want to clean files that are old, but I want to still preserve files that, for example, were downloaded from a server with an 'old' timestamp that both mtime and fd fail to process as required... Otherwise, I'd be cleaning files that users downloaded yesterday but were put online a few years ago.

I just hit this road bump myself

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

8 participants