Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sumonst21/c5c01b5991e10d053ebbd71d9e131acc to your computer and use it in GitHub Desktop.
Save sumonst21/c5c01b5991e10d053ebbd71d9e131acc to your computer and use it in GitHub Desktop.
How to remove files modified between particular dates?

The command GNU find is the way to go. For example, to delete all files in the current directory between 1 and 5 august, you can use the following command

find . -maxdepth 1 -type f -newermt 2011-08-01 ! -newermt 2011-08-06 -delete

It is better to execute the command without the -delete action, first, to see the listing of interested files (a good substitute could be -ls that produce an ls-like listing).

Removing the -maxdepth 1 specification will traverse all subdirectories, too.

You can also specify hours, for example

find . -maxdepth 1 -type f -newermt '2011-08-01 10:01:59' \
                         ! -newermt '2011-08-06 23:01:00' -delete

Be warned to not remove single quotes, that protect spaces between date and time.

The character ! is a negation, it should be read: newer that this date but not newer that this other date.

src: https://askubuntu.com/questions/57032/how-to-remove-files-modified-between-particular-dates

@sumonst21
Copy link
Author

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