≡ Menu

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

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 /
Share this tutorial on:

Your support makes a big difference:
I have a small favor to ask. More people are reading the nixCraft. Many of you block advertising which is your right, and advertising revenues are not sufficient to cover my operating costs. So you can see why I need to ask for your help. The nixCraft, takes a lot of my time and hard work to produce. If you use nixCraft, who likes it, helps me with donations:
Become a Supporter →    Make a contribution via Paypal/Bitcoin →   

Don't Miss Any Linux and Unix Tips

Get nixCraft in your inbox. It's free:

{ 8 comments… add one }
  • Travis November 23, 2009, 3:00 pm

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

    Thank’s Vivek!

  • King November 23, 2009, 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.

  • Vladimir November 24, 2009, 9:57 am

    Just a little addition – use tar’s -C

    tar cvf /dev/st0 -C /*

  • LightningCrash November 25, 2009, 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…

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

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

  • Kabuwa July 11, 2012, 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.

    • nixCraft July 11, 2012, 6:08 pm

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

  • mirakle November 24, 2016, 4:31 pm

    How to tar below filesystem in AIX and copy to another server
    /opt/db2/ – 2GB
    /opt/db2/data1 – 4GB

    when I tar /opt/db2/ , its considering 2+4=6GB.

Leave a Comment

You can use these HTML tags and attributes: <strong> <em> <pre> <code> <a href="" title="">

   Tagged with: , , , , , , , , , ,