With GNU or FreeBSD find
and GNU or BSD tar
:
find . -type f -newermt 2018-02-28 ! -newermt 2018-03-01 -print0 |
tar -cf file.tar --null -T -
(note that it excludes files last-modified at the exact nano-second 2018-02-28T00:00:00.000000000 (and could include a file at the time the next day) which on filesystems with nano-second granularity would almost never happen unless the files were created with touch -t
/touch -d
or were themselves extracted from archives that don't store timestamps with sub-second precision)
POSIXly and assuming file names don't contain newline characters (the standard tar archive format also has extra limitations on file names):
touch -d 2018-02-28T00:00:00 .start
touch -d 2018-03-01T00:00:00 .end
find . -type f -newer .start ! -newer .end ! -path ./.start ! -path ./.end |
pax -x ustar -w > file.tar
If you wanted all the regular files last modified on any Feb 28, not just 2018, with GNU tools:
find . -type f -printf '%Tm-%Td-%p\0' |
sed -nz 's/^02-28-//p' |
tar -cf file.tar --null -T -
The output of find -ls
is not post-processable automatically reliably, it's only intended for human consumption.
! -newermt 2016-02-29
. On Linux native file systems (as tagged by the OP), that would be one nano-second missing (and one possibly added) as already noted. With! -newermt 2018-02-28T23:59:59
, that's an entire second missing (1 billion as much), an entire minute with yourtouch -t
approach. Thefind -printf
approach doesn't have the issue. – Stéphane Chazelas Jul 23 '18 at 12:03find
does not have-newermt
. One would have to touch a separate file and use-newer
instead on this system. – Kusalananda Jul 23 '18 at 12:05-newermt
originated in BSDs, a shame OpenBSD didn't pick it up. – Stéphane Chazelas Jul 23 '18 at 12:06-newermt
looks like a nice enhancement forfind
and FreeBSD did already added an enhancement to their find that I invented in the 1980s: see-mtime -3y4w
and that is inlibfind
. – schily Jul 23 '18 at 12:10find
implementations since a while all support "unlimited" path length, all tar implementations exceptstar
don't support that. Star in the most recent version supports "unlimited" path length (8 GB) since a week viastar -c -find
and this week, there will be a new version that also supports unlimited path length using the vanillastar -c
command line. – schily Jul 23 '18 at 13:30gtar -c
but it cannot extract the so created archives andgtar -c -T -
still does not support long path names. – schily Jul 25 '18 at 10:37gtar -c
and cannot extract the own archives that have been created this way. – schily Jul 25 '18 at 10:50