-   Linux - Software (
-   -   Ignore specific sub directories when using tar (

MicahCarrick 11-15-2006 02:03 PM

Ignore specific sub directories when using tar

I want to backup my /home/mcarrick/ directory to a external usb drive mounted at /media/disk-1/, however, I want to ignore the 'downloads' and 'video' subdirectories. How can I do this?

I was using:


tar czf /media/disk-1/backup/local/mcarrick_11-15-2006.tar.gz /home/mcarrick/

unSpawn 11-16-2006 07:14 AM

Add "--exclude ~/somedirname"

kilgoretrout 11-16-2006 07:19 AM

Try this:

tar czf /media/disk-1/backup/local/mcarrick_11-15-2006.tar.gz --exclude=/downloads/ --exclude=/video/ /home/mcarrick/

matthewg42 11-16-2006 08:11 AM

You can also list the patterns you wish to exclude in a file, and use that like this:

echo "/home/mcarrick/video" >> ~/my_excludes
echo "/home/mcarrick/downloads" >> ~/my_excludes
tar czf /path/to/backup_file.tar.gz  --exclude-from=~/my_excludes /home/mcarrick/

Depending on how you are working, this may or may not be more easily maintainable than using multiple --exclude=... options on the command line. My personal opinion is that it is clearer if you have a lot of excludes to do, and is especially useful if you do frequent tar operations and every so often need to change the list.

{edit: changed ~/my_excludes filename mismatch between echo and tar commands}

MicahCarrick 11-16-2006 10:59 AM

Thank you!

All times are GMT -5. The time now is 08:04 PM.