Skip to main content
Make sure output goes to stdout and not to tape.
Source Link
Stéphane Chazelas
  • 584.6k
  • 96
  • 1.1k
  • 1.7k
find test -newer fileA

finds the test directory as well as the individual files therein, so tar adds test (and all its contents), then test/fileB and test/fileC.

Tighten your find to avoid this:

tar -c -v $(find test -type f -newer fileA) > test.tar

Note that using processcommand substitution in this way can cause issues e.g. with filenames containing spaces;spaces or wildcards; to avoid that, use

find test -type f -newer fileA -print0 | tar -c -v --null -T- -f - > test.tar

(with GNU find and tar), or

find test -type f -newer fileA -exec tar -ccvf -v {} + > test.tar

(assuming you don’t have too many files to archive).

find test -newer fileA

finds the test directory as well as the individual files therein, so tar adds test (and all its contents), then test/fileB and test/fileC.

Tighten your find to avoid this:

tar -c -v $(find test -type f -newer fileA) > test.tar

Note that using process substitution in this way can cause issues e.g. with filenames containing spaces; to avoid that, use

find test -type f -newer fileA -print0 | tar -c -v --null -T- > test.tar

(with GNU find and tar), or

find test -type f -newer fileA -exec tar -c -v {} + > test.tar

(assuming you don’t have too many files to archive).

find test -newer fileA

finds the test directory as well as the individual files therein, so tar adds test (and all its contents), then test/fileB and test/fileC.

Tighten your find to avoid this:

tar -c -v $(find test -type f -newer fileA) > test.tar

Note that using command substitution in this way can cause issues e.g. with filenames containing spaces or wildcards; to avoid that, use

find test -type f -newer fileA -print0 | tar -c -v --null -T- -f - > test.tar

(with GNU find and tar), or

find test -type f -newer fileA -exec tar cvf - {} + > test.tar

(assuming you don’t have too many files to archive).

Handle file names properly.
Source Link
Stephen Kitt
  • 480.9k
  • 59
  • 1.2k
  • 1.4k
find test -newer fileA

finds the test directory as well as the individual files therein, so tar adds test (and all its contents), then test/fileB and test/fileC.

Tighten your find to avoid this:

tar -c -v $(find test -type f -newer fileA) > test.tar

Note that using process substitution in this way can cause issues e.g. with filenames containing spaces; to avoid that, use

find test -type f -newer fileA -print0 | tar -c -v --null -T- > test.tar

(with GNU find and tar), or

find test -type f -newer fileA -exec tar -c -v {} + > test.tar

(assuming you don’t have too many files to archive).

find test -newer fileA

finds the test directory as well as the individual files therein, so tar adds test (and all its contents), then test/fileB and test/fileC.

Tighten your find to avoid this:

tar -c -v $(find test -type f -newer fileA) > test.tar
find test -newer fileA

finds the test directory as well as the individual files therein, so tar adds test (and all its contents), then test/fileB and test/fileC.

Tighten your find to avoid this:

tar -c -v $(find test -type f -newer fileA) > test.tar

Note that using process substitution in this way can cause issues e.g. with filenames containing spaces; to avoid that, use

find test -type f -newer fileA -print0 | tar -c -v --null -T- > test.tar

(with GNU find and tar), or

find test -type f -newer fileA -exec tar -c -v {} + > test.tar

(assuming you don’t have too many files to archive).

Source Link
Stephen Kitt
  • 480.9k
  • 59
  • 1.2k
  • 1.4k

find test -newer fileA

finds the test directory as well as the individual files therein, so tar adds test (and all its contents), then test/fileB and test/fileC.

Tighten your find to avoid this:

tar -c -v $(find test -type f -newer fileA) > test.tar