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?


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
  • 1
    Tar has no option --files-from, this is an option from gtar, so of you give such an advise, better mention that this is gtar specific. Find has no primary -not, this is another non-portable GNUism. In general, it is a bad idea to use a separate find call. This may give problems with funny characters in the filename and it definitely gives a low performance as both find and tar need to scan the filesystem. These problems do not apply to programs like star that use libfind and thus have the find code incorporated. – schily Sep 1 '15 at 8:36
  • Let me add another general hint: When giving an advise that is specific to a vendor specific variant of a UNIX program, it is good practice to mention the vendor and that it is vendor specific. This can typically be done by using the official names of the software, e.g gtar instead of tar, vim instead of vi. Note that this is a UNIX related information platform, so in general examples should be aligned with the POSIX standard. – schily Sep 1 '15 at 8:41
  • You're right, @schily, this is a GNU-specific solution. Your answer based on star is a good alternative and I have upvoted it for that reason. I also agree with the "funny characters" objection but since GNU tar does not have a -0 option it's a tradeoff. I do not agree with the performance objection, that's really of no consequence in this situation. – Celada Sep 1 '15 at 8:43
  • 2
    @schily, both GNU tar and bsdtar have --files-from and --null which removes the problem with funny characters (if combined with find's -print0 or -exec printf '%s\0' {} +). But here, you'd probably want to add the --no-recursion option. Some pax implementations also have a -0 option. – Stéphane Chazelas Sep 1 '15 at 12:23
  • 2
    @schily I feel that this comment thread is not the place for advocacy for different versions of tar. Please take it to chat. It's already way too long and reading like a religious war. Unless the OP chimes in at this point I don't think it matters what version of tar is in use. We don't even know what kind of Unix they are using. – Celada Sep 1 '15 at 13:06

My tar implementation is the best method

star -cv -f out.tar -find protTests ! -type l
  • 7
    zsh: command not found: star When you mention utilities that you know >99% of your readers won't have on your systems, explain where to get them. And you must disclose your affiliation when you mention your own product (whether you post the link or not, so you might as well post the link). – Gilles 'SO- stop being evil' Sep 1 '15 at 22:03
  • A typical Linux system these days misses a lot of important software after a default install and at the same time, a lot of useless software is installed. A Linux user should know how to install missing software and people who frequently use tar typically have star installed anyway. – schily Sep 1 '15 at 22:19
  • 8
    A vast majority of people who frequently use tar have never heard of pax, let alone star. – Gilles 'SO- stop being evil' Sep 1 '15 at 22:26
  • Well those people who don't know that they are using gtar on Linux when they call "tar" are probably not the people who care anyway. Star is the oldest free tar implementation and many features seen in various tar implementations have been taken from star, so why not talk about the original? – schily Sep 1 '15 at 22:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy