1

When tar-ing up large directories (ie. a home folder for a backup/OS reinstall), it is often okay to exclude certain large files such as multi-GB videos. However, due to the all-encompassing nature of a home folder, it is often unrealistic to remember each and every file that may be useful to exclude (with --exclude) before starting. I am looking for some sort of input that I can give to tar to tell it to quit whatever file it's on and move onto the next, leaving the quitt-ed file out of the archive. Perhaps like a control-C, but instead of stopping the entire process, simply stop the current file.

Specifically, I am referring to a long running tar -cvf or tar -cvzf. As both of these commands contain -v it is easy to determine what file tar is currently on.

Using any sort of GUI tool is not an option, as tar is often run in a minimal (CLI only) environment on a broken system before a reinstall. This is the specific case I am asking about.

  • There is no --exclude in tar, you may have a vendor specific implementation in mind. – schily Oct 1 '15 at 10:13
  • @schilly There is: stackoverflow.com/questions/984204/…. Also, a screenshot of part of the man page: i.imgur.com/Y5tELkP.png – john01dav Oct 1 '15 at 19:39
  • You are not talking about the man page for tar but rather the man page for gtar. – schily Oct 1 '15 at 19:57
  • @schily The question specifies Ubuntu. On Ubuntu, tar is GNU tar and there is no gtar. Please stop confusing people by pretending that Unix variants other than your favorite one don't exist. – Gilles Oct 1 '15 at 23:14
  • You might be able to do that with a variant of the gdb usage in my answer to this related question, with close or lseek(fd, 0, 2) instead of truncate. I'm not posting this as an answer because I'm not sure it would work, it may well crash tar. – Gilles Oct 1 '15 at 23:20
0

I don't think that is possible, but you might simply just exclude large files automatically from your tar. For example,

find mydir ! -type f -o \( -type f -size -1000k \) | tar cv --no-recursion -T - -f /tmp/tar 

which does not save files bigger than 1000k.


Here's a script to ask interactively for a "n" reply to stop big files being archived:

find mydir \( -type f -size +1000k -exec /tmp/biggie {} \; \) -o -print |
tar c --no-recursion -T - -f /tmp/tar

where /tmp/biggie is the script

#!/bin/bash
if ! read -t 10 -n 1 -p "$1 ok ?" reply || [ n != "$reply" ]
then echo >&2
     echo "$1"
else echo " ignoring $1" >&2
fi

which does a bash-specific read with timeout of 10 seconds of 1 char (-n), with the filename as prompt (-p). If you type "n" within 10 seconds the file is ignored.

  • There are some large files I want to save though. I want whatever program I am using to allow me to decide on a case-by-case basis without manually going through the entire directory structure. Perhaps it would be helpful to have it ask me for any files over 1G and then archive them if it doesn't get a response within 10 seconds (to allow for unattended backups). – john01dav Oct 1 '15 at 18:45
  • I've added a script to do that. – meuh Oct 1 '15 at 19:16
0

There is of course no way to tell a running program to change it's initial setup unless this program asks you for this.

If you just like to avoid large files, I recommend to use star instead of the non-standard tar you are already using.

star -c -f out.tar -find startdir -size -1g

Use the appropriate size instead of the 1G in the example.

This is much faster than using a separate find program call and this avoids side-effects from funny characters in filenames.

  • There are some large files I want to save though. I want whatever program I am using to allow me to decide on a case-by-case basis without manually going through the entire directory structure. Perhaps it would be helpful to have it ask me for any files over 1G and then archive them if it doesn't get a response within 10 seconds (to allow for unattended backups). – john01dav Oct 1 '15 at 18:45
  • find allows to write even complex rules, so there should be a way to describe what you like. – schily Oct 1 '15 at 19:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.