Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have the following bash script that creates a tar.gz of my filesystem on a Kubuntu PC. The problem is, that it also tries to backup the tar.gz backup file, even though I am storing the backup in /tmp and omitting /tmp from the backup. I am wondering why it's backing up the file in /tmp even though I told it not to.

# init

DATE=$(date +20%y%m%d)

sudo tar -cvpzf /tmp/`hostname`_$DATE.tar.gz \
--exclude=/proc \
--exclude=/lost+found \
--exclude=/sys \
--exclude=/mnt \
--exclude=/media \
--exclude=/dev \
--exclude=/tmp \
--exclude=/home/jlacroix/Desktop \
--exclude=/home/jlacroix/Documents \
--exclude=/home/jlacroix/Music \
--exclude=/home/jlacroix/Pictures \
--exclude=/home/jlacroix/Projects \
--exclude=/home/jlacroix/Roms \
--exclude=/home/jlacroix/Videos \
--exclude=/home/jlacroix/.VirtualBox\ VMs \
--exclude=/home/jlacroix/.SpiderOak \

scp /tmp/`hostname`_$DATE.tar.gz jlacroix@Pluto:/share/Recovery/Snapshots

sudo rm /tmp/`hostname`_$DATE.tar.gz
share|improve this question
That's weird... it works for me when I try something similar to your example. Are you seeing the /tmp/hostname_date.tar.gz file in the -v output from tar, or how do you know that it's being included? – nilbus Nov 23 '12 at 15:33
Unrelated: Is there a particular reason you’re using 20%y rather than %Y? – Claudius Nov 23 '12 at 15:47
I watch the output, and see it in the process of backing up /tmp/hostname_date.tar.gz, so I CTRL+C to bail out. I am using +20%y because I want the output to be 2012 instead of just 12. – Jay LaCroix Nov 23 '12 at 16:22
@JayLaCroix %Y = 2012, %y = 12, although it's not a huge deal since either way it accomplishes your goal. Just minutely cleaner. – nerdwaller Nov 23 '12 at 16:26
Thanks for that. – Jay LaCroix Nov 23 '12 at 16:31

You need to add "*" behind the excluded paths, how it works is the algorithm excludes the Pattern, not the directory.

So the pattern /home/jlacroix/Music != /home/jlacroix/Music/*

Give that a shot, works for me here.


That still backs up the directory name, however. So really you need it to look like this:

--exclude=/home/[username]/Music/* --exclude=/home/[username]/Music \

That would carry true for the remainder of items.

share|improve this answer
It's my fault! It turns out it wasn't backing up the archive, it was copying the archive to the server, and I mistook that for it copying the archive into the archive. Sorry! – Jay LaCroix Nov 23 '12 at 17:04

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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