zsh-users
 help / color / mirror / code / Atom feed
* finding symlinks without target
@ 1998-01-23 14:47 Sven Guckes
  1998-01-23 15:12 ` Bernd Eggink
                   ` (3 more replies)
  0 siblings, 4 replies; 8+ messages in thread
From: Sven Guckes @ 1998-01-23 14:47 UTC (permalink / raw)
  To: ZShell Users

Hi!

Problem:
Find (and print) all symbolic links without a target within the current dirtree.

Anyone hints?

Sven


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: finding symlinks without target
  1998-01-23 14:47 finding symlinks without target Sven Guckes
@ 1998-01-23 15:12 ` Bernd Eggink
  1998-01-23 15:26 ` Bruce Stephens
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 8+ messages in thread
From: Bernd Eggink @ 1998-01-23 15:12 UTC (permalink / raw)
  To: Sven Guckes; +Cc: ZShell Users

Sven Guckes wrote:
> 
> Hi!
> 
> Problem:
> Find (and print) all symbolic links without a target within the current dirtree.
> 
> Anyone hints?

Not too elegant, but it works:

   for d in *(@); do cat $d >/dev/null 2>&1 || print $d; done

Bernd

--
Bernd Eggink
Regionales Rechenzentrum der Uni Hamburg
eggink@rrz.uni-hamburg.de
http://www.rrz.uni-hamburg.de/eggink/BEggink.html


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: finding symlinks without target
  1998-01-23 14:47 finding symlinks without target Sven Guckes
  1998-01-23 15:12 ` Bernd Eggink
@ 1998-01-23 15:26 ` Bruce Stephens
  1998-01-23 16:00 ` Bart Schaefer
  1998-01-23 17:51 ` Peter Williams
  3 siblings, 0 replies; 8+ messages in thread
From: Bruce Stephens @ 1998-01-23 15:26 UTC (permalink / raw)
  To: ZShell Users

guckes@math.fu-berlin.de said:
> Find (and print) all symbolic links without a target within the
> current dirtree. 

For big dirtrees, this is probably a job for find.  I can't see immediately 
how to do it in zsh.

**/*(@) gives the list of symbolic links, and **/*(-@) gives the list of 
symbolic links with targets which do exist.  Clearly, from this one can 
calculate the list of symbolic links which don't have existing targets, but 
there ought to be an easier way of doing it.



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: finding symlinks without target
  1998-01-23 14:47 finding symlinks without target Sven Guckes
  1998-01-23 15:12 ` Bernd Eggink
  1998-01-23 15:26 ` Bruce Stephens
@ 1998-01-23 16:00 ` Bart Schaefer
  1998-01-23 16:42   ` Bruce Stephens
  1998-01-23 16:47   ` finding symlinks without target Peter Williams
  1998-01-23 17:51 ` Peter Williams
  3 siblings, 2 replies; 8+ messages in thread
From: Bart Schaefer @ 1998-01-23 16:00 UTC (permalink / raw)
  To: Sven Guckes, ZShell Users

On Jan 23,  3:47pm, Sven Guckes wrote:
} Subject: finding symlinks without target
}
} Find (and print) all symbolic links without a target within the current
} dirtree.

	file **/*(D@) | fgrep broken

(You may need to change the grep if you're not using GNU `file`.)

Oh, you want it all in zsh?

	for i in **/*(D@); [[ -f $i || -d $i ]] || echo $i

But I think the pipe to fgrep would be faster.  (Why isn't there a glob
qualifier to chase links?  **/*(@^.,@^/) would appear to be perfect, but
doesn't work.)

-- 
Bart Schaefer                                 Brass Lantern Enterprises
http://www.well.com/user/barts              http://www.brasslantern.com


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: finding symlinks without target
  1998-01-23 16:00 ` Bart Schaefer
@ 1998-01-23 16:42   ` Bruce Stephens
  1998-01-23 17:10     ` zsh manual - more examples! Sven Guckes
  1998-01-23 16:47   ` finding symlinks without target Peter Williams
  1 sibling, 1 reply; 8+ messages in thread
From: Bruce Stephens @ 1998-01-23 16:42 UTC (permalink / raw)
  To: Bart Schaefer; +Cc: ZShell Users

schaefer@brasslantern.com said:
> (Why isn't there a glob qualifier to chase links?  **/*(@^.,@^/) would
> appear to be perfect, but doesn't work.) 

There is, isn't there.  The - seems to be right, almost.  How about 
**/*(@-^.,@-^/)

Meaning those symbolic links whose referents aren't files or directories?  On 
the other hand, I'll bet this won't work, because the property of existence is 
probably required when globbing.  The question is a good one though: there 
ought to be a way of doing this, and it probably ought to be an example in the 
manual, because it's a common enough task, and it would be cool to have a 
one-liner for small trees.



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: finding symlinks without target
  1998-01-23 16:00 ` Bart Schaefer
  1998-01-23 16:42   ` Bruce Stephens
@ 1998-01-23 16:47   ` Peter Williams
  1 sibling, 0 replies; 8+ messages in thread
From: Peter Williams @ 1998-01-23 16:47 UTC (permalink / raw)
  To: ZShell Users

In message <980123080024.ZM16631@candle.brasslantern.com>, "Bart Schaefer" writ
es:
 >	file **/*(D@) | fgrep broken
 >
 >(You may need to change the grep if you're not using GNU `file`.)
 >
 >Oh, you want it all in zsh?
 >
 >	for i in **/*(D@); [[ -f $i || -d $i ]] || echo $i
 >
 >But I think the pipe to fgrep would be faster.  (Why isn't there a glob
 >qualifier to chase links?  **/*(@^.,@^/) would appear to be perfect, but
 >doesn't work.)

You could also implement it as a function with perl:

badsyms () {
    perl -e '{
        require "find.pl";
        sub wanted { !stat($_) && print("$name\n") }
        &find(@ARGV);
    }' $*
}

However, this seems a bit slower than M. Schaefer's solutions above.

Peter Williams <peter.williams@jpl.nasa.gov>

------------------ SITUATION: New Account Creation -------------------
ADMINISTRATIVE FASCIST:  Puts new account policy in motd.  Since
  people without accounts cannot read the motd, nobody ever fulfills
  the bureaucratic requirements; and so, no new accounts are ever
  created.
  -- Stephan Zielinski, "KNOW YOUR UNIX SYSTEM ADMINISTRATOR"


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: zsh manual - more examples!
  1998-01-23 16:42   ` Bruce Stephens
@ 1998-01-23 17:10     ` Sven Guckes
  0 siblings, 0 replies; 8+ messages in thread
From: Sven Guckes @ 1998-01-23 17:10 UTC (permalink / raw)
  To: ZShell Users

Quoting Bruce Stephens (B.Stephens@isode.com):
> [...] the property of existence is probably required when globbing.
> The question is a good one though: there ought to be a way of doing this,
> and it probably ought to be an example in the manual, because it's a common
> enough task, and it would be cool to have a one-liner for small trees.

Indeed - it seems such a basic problem that it ought be in the manual.
Btw, I find that manuals have way too far examples.  While I can understand
that not every example should be in a manual, the users would benefit A LOT
if the manual to their shell (read: ZShell) had more examples.

For now, I'll be adding more exmaples to my page about the zsh:

	http://www.math.fu-berlin.de/~guckes/zsh/

Sven


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: finding symlinks without target
  1998-01-23 14:47 finding symlinks without target Sven Guckes
                   ` (2 preceding siblings ...)
  1998-01-23 16:00 ` Bart Schaefer
@ 1998-01-23 17:51 ` Peter Williams
  3 siblings, 0 replies; 8+ messages in thread
From: Peter Williams @ 1998-01-23 17:51 UTC (permalink / raw)
  To: ZShell Users

In message <19980123154701.05885@math.fu-berlin.de>, Sven Guckes writes:
 >Hi!
 >
 >Problem:
 > Find (and print) all symbolic links without a target within the
 > current dirtree.

Why not implement it as a function with perl:

badsyms () {
    perl -e '{
        require "find.pl";
        sub wanted { !stat($_) && print("$name\n") }
        &find(@ARGV);
    }' $*
}

Peter Williams <peter.williams@jpl.nasa.gov>

------------------ SITUATION: New Account Creation -------------------
ADMINISTRATIVE FASCIST:  Puts new account policy in motd.  Since
  people without accounts cannot read the motd, nobody ever fulfills
  the bureaucratic requirements; and so, no new accounts are ever
  created.
  -- Stephan Zielinski, "KNOW YOUR UNIX SYSTEM ADMINISTRATOR"


^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~1998-01-23 18:04 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1998-01-23 14:47 finding symlinks without target Sven Guckes
1998-01-23 15:12 ` Bernd Eggink
1998-01-23 15:26 ` Bruce Stephens
1998-01-23 16:00 ` Bart Schaefer
1998-01-23 16:42   ` Bruce Stephens
1998-01-23 17:10     ` zsh manual - more examples! Sven Guckes
1998-01-23 16:47   ` finding symlinks without target Peter Williams
1998-01-23 17:51 ` Peter Williams

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).