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 /

🐧 Get the latest tutorials on Linux, Open Source & DevOps via RSS feed or Weekly email newsletter.

🐧 8 comments so far... add one

CategoryList of Unix and Linux commands
Disk space analyzersncdu pydf
File Managementcat
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network UtilitiesNetHogs dig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg jobs killall kill pidof pstree pwdx time
Searchinggrep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNAlpine CentOS 8 Debian 10 Firewall Ubuntu 20.04
8 comments… add one
  • Travis Nov 23, 2009 @ 15:00

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

    Thank’s Vivek!

  • King Nov 23, 2009 @ 17:09

    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 Nov 24, 2009 @ 9:57

    Just a little addition – use tar’s -C

    tar cvf /dev/st0 -C /*

  • LightningCrash Nov 25, 2009 @ 17:52

    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 Dec 4, 2009 @ 6:57

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

  • Kabuwa Jul 11, 2012 @ 15:58

    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 Jul 11, 2012 @ 18:08

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

  • mirakle Nov 24, 2016 @ 16:31

    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 Reply

Your email address will not be published.

Use HTML <pre>...</pre> for code samples. Still have questions? Post it on our forum