Skip to main content
added 701 characters in body; added 1 character in body; added 86 characters in body
Source Link
igal
  • 10.2k
  • 4
  • 45
  • 60

You'reEach of your two approaches was close to working, but each had a distinct problem.

In your first approach you try to pipe a list of files to tar. If you want tar to read the list of files from standard input then you have to use the -T/--files-from and - options, e.g.

find -name '*.png' -print0 | tar -cvf backup.tar --null -T - 

For a reference, see the official documentation:

NOTE: The use of the -print0 and --null flags should ensure that this also handles filenames which include whitespace.

In your second approach you try to run tar via xargs, but you're using the "create" option (--create / -c) for tar. If you call this in a loop (oruse the "create" option with xargs) or in a for-loop, then it will overwrite the archive after every iteration. Instead, try using either the "append" option (-a / --append) or the "update" option (-u / --update), e.g.:

find -name "*.png" -exec tar -uvf backupp.tar {} \;

This will append files to the archive after each iteration instead of over-writing it.

ThenEither way, once you're done you can use the "list" option (--list / -t) to view the contents of the archive and verify that everything worked as expected:

tar tf backupp.tar

You're using the "create" option (--create / -c) for tar. If you call this in a loop (or with xargs) then it will overwrite the archive after every iteration. Instead, try using either the "append" option (-a / --append) or the "update" option (-u / --update), e.g.:

find -name "*.png" -exec tar -uvf backupp.tar {} \;

This will append files to the archive after each iteration instead of over-writing it.

Then you can use the "list" option (--list / -t) to view the contents of the archive and verify that everything worked as expected:

tar tf backupp.tar

Each of your two approaches was close to working, but each had a distinct problem.

In your first approach you try to pipe a list of files to tar. If you want tar to read the list of files from standard input then you have to use the -T/--files-from and - options, e.g.

find -name '*.png' -print0 | tar -cvf backup.tar --null -T - 

For a reference, see the official documentation:

NOTE: The use of the -print0 and --null flags should ensure that this also handles filenames which include whitespace.

In your second approach you try to run tar via xargs, but you're using the "create" option (--create / -c). If you use the "create" option with xargs or in a for-loop, then it will overwrite the archive after every iteration. Instead, try using either the "append" option (-a / --append) or the "update" option (-u / --update), e.g.:

find -name "*.png" -exec tar -uvf backupp.tar {} \;

This will append files to the archive after each iteration instead of over-writing it.

Either way, once you're done you can use the "list" option (--list / -t) to view the contents of the archive and verify that everything worked as expected:

tar tf backupp.tar
Source Link
igal
  • 10.2k
  • 4
  • 45
  • 60

You're using the "create" option (--create / -c) for tar. If you call this in a loop (or with xargs) then it will overwrite the archive after every iteration. Instead, try using either the "append" option (-a / --append) or the "update" option (-u / --update), e.g.:

find -name "*.png" -exec tar -uvf backupp.tar {} \;

This will append files to the archive after each iteration instead of over-writing it.

Then you can use the "list" option (--list / -t) to view the contents of the archive and verify that everything worked as expected:

tar tf backupp.tar