75

Is it possible and how can I zip a symlink from a linux shell?

Caleb
  • 11,583
  • 4
  • 35
  • 49
DucDigital
  • 1,441
  • 3
  • 18
  • 26

2 Answers2

90

You can store symlinks as symlinks (as opposed to a copy of the file/directory they point to) using the --symlinks parameter of the standard zip.

Assuming foo is a directory containing symlinks:

zip --symlinks -r foo.zip foo/

Rar equivalent:

rar a -ol foo.rar foo/

tar stores them as is by default.

tar czpvf foo.tgz foo/

Note that the symlink occupies almost no disk space by itself (just an inode). It's just a kind of pointer in the filesystem, as you probably know.

Eduardo Ivanec
  • 14,531
  • 1
  • 35
  • 42
  • 1
    i can't use tar, but the --symlinks is not working with zip. are you sure it's the default zip package? – DucDigital May 03 '11 at 03:33
  • Which distribution you've got? `Copyright (c) 1990-2008 Info-ZIP - Type 'zip "-L"' for software license. Zip 3.0 (July 5th 2008).` Can you use rar instead? See added example. – Eduardo Ivanec May 03 '11 at 03:39
  • Copyright (c) 1990-2006 Info-ZIP. All rights reserved. This is Zip 2.32 probably because of this. i will try rar – DucDigital May 03 '11 at 04:03
  • 1
    Splitting hairs, but technically the symlink does occupy disk space, consuming an inode. – ttyS0 May 03 '11 at 04:06
  • True that. Actually from what I read in the past they were even more like regular files containing the path to the pointed file/directory. Now they're just a special kind of inode if I remember correctly. – Eduardo Ivanec May 03 '11 at 04:13
  • what about 7z in windows? – Banee Ishaque K Mar 31 '19 at 14:51
13

On RHEL 5, we have

$ zip -h
Copyright (C) 1990-2005 Info-ZIP
Type 'zip "-L"' for software license.
Zip 2.31 (March 8th 2005). Usage:
zip [-options] [-b path] [-t mmddyyyy] [-n suffixes] [zipfile list] [-xi list]
(snip)
  -y   store symbolic links as the link instead of the referenced file
nodakai
  • 291
  • 3
  • 8