Linux / UNIX: tar Command Stay In Local / File System When Creating Archive

by on November 23, 2009 · 7 comments· LAST UPDATED December 5, 2009

in , ,

I'd like to make / file system backup but the problem is there are other file systems mounted under / such as:


I'd like to skip all other file systems mounted at / and only make backup of local / and not /boot, /var, /iscsi, and /mnt/cdrom etc. How do I force tar to use a single file system under Linux / UNIX / BSD operating systems?

The --one-file-system option ask the tar command not to cross mount points and stay in local file system when creating / updating archives. The syntax is as follows:

tar zcvf /path/to/file.tar.gz  --one-file-system fileSystems
tar zcvf /path/to/file.tar.gz  --one-file-system /

In this example, make a backup of / file system to /dev/st0 without crossing file system boundaries, enter:

tar cvf /dev/st0  --one-file-system /
Tweet itFacebook itG+ itDownload PDF versionFound an error/typo on this page?

{ 7 comments… read them below or add one }

1 Travis November 23, 2009 at 3:00 pm

It seems whenever I think of a problem you immediately post the solution.

Thank’s Vivek!


2 King November 23, 2009 at 5:09 pm

Old habit for me is rather than using absolute pathname for root, you cd there and use the relative pathname “.” instead. Old versions of tar would restore the file exactly as it was created in the archive, so if you did this:

tar cvf /dev/st0 /

it created a tar file that could only be restored in /. Whereas if you do this:

cd /
tar cvf /dev/st0 .

you get a tar file that can be restored anywhere (including root as long as you cd there first).

Yes, many versions of tar have fixed this and Linux strips leading /s by default, but unless you’re sure and there’s no chance you may ever take your tar file to another machine (say an old Unix box), this is an easy way to be sure.


3 Vladimir November 24, 2009 at 9:57 am

Just a little addition – use tar’s -C

tar cvf /dev/st0 -C /*


4 LightningCrash November 25, 2009 at 5:52 pm

I seem to recall if you explicitly call a directory, tar will ignore your one-file-system argument for that case.

Ie if you execute
tar cvzf /path/to/file.tar.gz --one-file-system /*
You’ll end up with /sys and /proc et al, because you globbed them in!

Definitely test it before you send it after 1TB of data…


5 Peg Perego Uno Stroller December 4, 2009 at 6:57 am

great post as usual .. thanks .. you just gave me a few more ideas to play with


6 Kabuwa July 11, 2012 at 3:58 pm

would like to put my root to tape on the hp dds-4c5718A. using the unix command, how do i do it. when using the tar cvf /dev/st0 /* and Iam getting an error message
tar: Error exit delayed from previous errors.


7 nixCraft July 11, 2012 at 6:08 pm

Are you using Linux or Unix (Solaris / HP -UX / AIX and so on)?


Leave a Comment

Tagged as: , , , , , , , , , ,

Previous Faq:

Next Faq: