I would like to backup my entire home directory on Linux. Suppose this directory is the only one I have write permissions to.

How would I tar-gzip this directory and put result inside itself?

  • You have write permission for /tmp, too. Commented Jul 30, 2018 at 8:14

3 Answers 3


tar zcf home-backup.tar.gz --exclude ./home-backup.tar.gz .

  • 1
    That would exclude any file called home-backup.tar.gz not only the one you're creating here. With GNU tar (not with bsdtar), you can use --exclude ./home-backup.tar.gz to avoid it. Commented Jul 30, 2018 at 15:00
  • good idea (edit: added ./ to exlcude just the one file)
    – Jasen
    Commented Jul 31, 2018 at 8:26

The already suggested

tar zcf home-backup.tar.gz --exclude home-backup.tar.gz .

would work, but I don't really like that kind of tars which contain lots of files instead of only one directory. If you want to do the same but as one directory:

cd /home
tar -czf yourhome/yourhome.tgz --exclude yourhome.tgz yourhome/

In both case you will get an error message:

tar: yourhome: file changed as we read it

which can be a problem if you want to backup from a script and checking the exit code, and anyway if you ignore this it could hide another problem. You can eliminate this creating an empty tgz before you start the backup:

touch yourhome.tgz
  • You mention another reason for avoiding GNU tar.
    – schily
    Commented Jul 30, 2018 at 14:43
  • Avoiding a built in well known tool is not always easy. Especially when you don't have root permissions (like in the main question here).
    – redseven
    Commented Jul 30, 2018 at 23:18
  • Even though GNU tar is 5 years younger than star, it had plenty of authors and this is not good. Fixing a reported bug typically takes 20 years and the 1993 announced incremental restore still only works with trivial changes between two incrementals. I am happy if GNU tar unpacks schilytools, so I can compile star ;-) You don't need to be root to do that.
    – schily
    Commented Jul 31, 2018 at 9:23

If you use a working modern tar implementation, this will work the way you like out of the box:

star -cz . > archive.tar.gz

will print the warning:

star: 'archive.tar.gz' is the archive. Not dumped.
  • That also seems to work in libarchive bsdtar, but not GNU tar. tar zcf archive.tar.gz . works with my version of GNU tar, but causes the directory modified warning mentioned by @redseven. Commented Jul 31, 2018 at 8:30
  • libarchive is quiet but if you take a closer look, it is better than GNU tar.
    – schily
    Commented Jul 31, 2018 at 9:24

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .