I have a directory with files, subdirectories and symlinks

How to zip only files and folders from that directory without symlinks or files referred to by the symlink?

  • 1
    Do you mean store symlinks, but not files (instead of symlinks)? – Romeo Ninov Dec 26 '18 at 16:30
  • Do you want the files the symlinks point to? – phk Dec 26 '18 at 16:46
  • I'd rsync the directory into a sibling if possible, and hardlink the files (to reduce diskspace), then (depending on the version of rsync...) find/delete the symbolic links in the sibling directory, and zip/move the contents of the sibling directory (finish by removing the top-level sibling). – Thomas Dickey Dec 26 '18 at 17:03
  • I want to zip only ordinary files and folders, not symlinks nor the files referred to by the symlink – mlsvmldkv110011 Dec 26 '18 at 17:04

You could use @exclude_file: save the symlinks and their target paths1 in a text file then zip the directory and use that file to exclude those paths e.g.

find /full/path/to/dir -type l -print -exec readlink -f {} \; > exclude.lst
zip -r myarchive /full/path/to/dir -x@exclude.lst

1: assuming sane filenames

Your Answer

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

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