Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a directory with symbolic links to other directories. I want to archive the symbolic links, not as links but as archives containing the files of directories they refer to, using tar command. How can I do this?

share|improve this question
up vote 36 down vote accepted

Use the -h tar option. From the man page:

-h, --dereference
    don't archive symlinks; archive the files they point to
share|improve this answer
If I have /sym1 points to /backups and /sym2 points to /backups, then I run tar -hcf file.tar /sym1 /sym2 will I get /backups twice? – Felipe Alvarez Jan 28 '15 at 23:55
Why not try it and see? – kojow7 Mar 14 at 5:04

If the links are all in the root directory you can have the shell dereference them and pass to tar as arguments. For example if you have /backup/source/a and /backup/source/b, both of which are symlinks pointing to the real directory, something like the following would work

tar -cf /path/to/backup.tar /backup/source/*/
share|improve this answer
Doesn't work here. Seems like tar -cf /path/to/backup.tar /backup/source/a/ alone doesn't even work when a is a symlink. – Zero3 Jan 3 at 19:52

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.