Skip to main content
added 268 characters in body
Source Link
Stéphane Chazelas
  • 584.6k
  • 96
  • 1.1k
  • 1.7k

With zsh (you're actually using zsh syntax in your code; with bash, you'd need to quote those variables):

rm -- $target/*(-@)

Or:

rm -- $target/<20150101-20151231>.log.gz(-@)

*(@) matches the files of type symlink. *(-@) are the ones that are still of type symlink after symlink resolution (that is, those for which the target of the symlink can't be resolved). That's equivalent to GNU find's -xtype l.

In zsh and with GNU ln, you'd rather write your loop as:

ln -srt $target -- $origin/<20150101-20151231>.log.gz

Which would also work even if $origin contains a relative path (and creates relative symlinks which reduces the risk of symlinks to be broken if some path components of the origin (the ones that are common with that of the target) are renamed in the future).

With zsh (you're actually using zsh syntax in your code; with bash, you'd need to quote those variables):

rm -- $target/*(-@)

Or:

rm -- $target/<20150101-20151231>.log.gz(-@)

*(@) matches the files of type symlink. *(-@) are the ones that are still of type symlink after symlink resolution (that is, those for which the target of the symlink can't be resolved). That's equivalent to GNU find's -xtype l.

In zsh and with GNU ln, you'd rather write your loop as:

ln -srt $target -- $origin/<20150101-20151231>.log.gz

With zsh (you're actually using zsh syntax in your code; with bash, you'd need to quote those variables):

rm -- $target/*(-@)

Or:

rm -- $target/<20150101-20151231>.log.gz(-@)

*(@) matches the files of type symlink. *(-@) are the ones that are still of type symlink after symlink resolution (that is, those for which the target of the symlink can't be resolved). That's equivalent to GNU find's -xtype l.

In zsh and with GNU ln, you'd rather write your loop as:

ln -srt $target -- $origin/<20150101-20151231>.log.gz

Which would also work even if $origin contains a relative path (and creates relative symlinks which reduces the risk of symlinks to be broken if some path components of the origin (the ones that are common with that of the target) are renamed in the future).

Source Link
Stéphane Chazelas
  • 584.6k
  • 96
  • 1.1k
  • 1.7k

With zsh (you're actually using zsh syntax in your code; with bash, you'd need to quote those variables):

rm -- $target/*(-@)

Or:

rm -- $target/<20150101-20151231>.log.gz(-@)

*(@) matches the files of type symlink. *(-@) are the ones that are still of type symlink after symlink resolution (that is, those for which the target of the symlink can't be resolved). That's equivalent to GNU find's -xtype l.

In zsh and with GNU ln, you'd rather write your loop as:

ln -srt $target -- $origin/<20150101-20151231>.log.gz