Tar command – skip symlinks

filessymlinktarwildcards

I use the tar command as,

tar -cvf protTests.tar protTests/*

to tar all files inside the folder, protTests. But this is including the symbolic links inside the folder, which is not a desired one.

Is there a command line option, that will leave out all symlinks?

Best Answer

You could do this, to supply tar with a list of all files inside protTests except those which are symlinks:

find protTests -maxdepth 1 -mindepth 1 -not -type l -print0 |
  tar --null --files-from - -cvf protTests.tar

By the way, your existing command:

tar -cvf protTests.tar protTests/*

will not archive all files in protTests, it will only archive those whose names do not begin with . (those that are not hidden). The * glob operator skips files whose names begin with . by design. The command also has the problem that if protTests has lots of files (more than many thousand), then protTests/* can expand to too many arguments to fit on the command line.

A simpler command like this would have neither of those problems:

tar -cvf protTests.tar protTests