2

I'm trying to create a compressed TAR file. I have a disk that I am going to destroy and would like to take one last snapshot of the /users folder but don't want the users .m4v .m4a and .mp3 files as they are too large.

I tried using this command line

sudo tar acvf- -exclude='*.m4v' -exclude='*.m4a' -exclude='*.mp3' /home/john/Desktop/KS_UserFolders.tar.gz media/john/OS/Users/

The message that I get back is

john@Pepper:~$ sudo tar acvf- -exclude='*.m4v' -exclude='*.m4a' -exclude='*.mp3' /home/john/Desktop/KS_UserFolders.tar.gz media/john/OS/Users/
[sudo] password for john:
tar: -exclude=*.m4a: Cannot stat: No such file or directory
tar: -exclude=*.mp3: Cannot stat: No such file or directory
tar: Removing leading `/' from member names
tar: /home/john/Desktop/KS_UserFolders.tar.gz: Cannot stat: No such file or directory
tar: media/john/OS/Users: Cannot stat: No such file or directory
tar: Exiting with failure status due to previous errors
john@Pepper:~$ 

I'm sure it's just me getting used to the syntax of Linux, but I can't find a good usage example of TAR that matches my situation, and version of TAR

  • 1) it should be --exclude (with two dashes), not -exclude. 2) You may need to use tar's --wildcards option, which I found by looking at the man page (man tar): "--wildcards : use wildcards with --exclude" – Nick Weinberg Jun 29 '16 at 0:03
  • I was on that Man page like a fat kid on a piece of cake. The entry for Wildcards say their enabled by default for exclusions :/ – dotdawtdaught Jun 29 '16 at 3:50
2

Try

sudo tar acvf /home/john/Desktop/KS_UserFolders.tar.gz \
  --exclude='*.m4v' \
  --exclude='*.m4a' \
  --exclude='*.mp3' media/john/OS/Users/

Note that the archive file name must come right after the f option (without a -), and the --exclude options need two dashes.

If you want it all on one line, it would be

sudo tar acvf /home/john/Desktop/KS_UserFolders.tar.gz --exclude='*.m4v' --exclude='*.m4a' --exclude='*.mp3' media/john/OS/Users/
  • Now it's reporting that there is no such file or directory as --exclude='.m4v' --exclude='.m4a' I noticed the syntax of your response includes CR, I assume that the this was just the board munging your post. – dotdawtdaught Jun 29 '16 at 3:48
  • @dotdawtdaught : Did you include the asterisks in steeldriver 's answer? (And the carriage returns are just for readability) – Nick Weinberg Jun 29 '16 at 9:25
  • I did include the asterisks. – dotdawtdaught Jun 29 '16 at 23:16
  • OK, my apologies -- that was just AskUbuntu's software interpreting your asterisks as italics markers – Nick Weinberg Jun 30 '16 at 1:37
  • No worries, this is a strange issue. I can't find a syntax reference that elaborates on how to use the -X or -exclude switches for multiple exclusions. – dotdawtdaught Jul 6 '16 at 7:32

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.