how to have "find" not list bad symbolic links?

how to have "find" not list bad symbolic links?

Post by Jens-Ulrik Holger Peterse » Thu, 11 Sep 1997 04:00:00



I want to ask: is it possible to get `find' to list everything except
bad symbolic links (ie symlinks that point to nothing)?

How does one do it?

(Mail copies of replies appreciated.)

Thank you, Jens

 
 
 

how to have "find" not list bad symbolic links?

Post by Shawn McPe » Thu, 11 Sep 1997 04:00:00



Quote:>I want to ask: is it possible to get `find' to list everything except
>bad symbolic links (ie symlinks that point to nothing)?
>How does one do it?
>(Mail copies of replies appreciated.)

Here's a tcsh "solution" that I use:

( find . -whatever -ls > /dev/tty ) >& /dev/null

Obviously if you're using ksh or similar shell, you can just redirect
stderr to /dev/null, but I don't use ksh interactively.

Shawn

 
 
 

how to have "find" not list bad symbolic links?

Post by Jens-Ulrik Holger Peterse » Fri, 12 Sep 1997 04:00:00


Thanks for replying.


    >> I want to ask: is it possible to get `find' to list everything
    >> except bad symbolic links (ie symlinks that point to nothing)?

    >> How does one do it?

    >> (Mail copies of replies appreciated.)

    Shawn> Here's a tcsh "solution" that I use:

    Shawn> ( find . -whatever -ls > /dev/tty ) >& /dev/null

    Shawn> Obviously if you're using ksh or similar shell, you can
    Shawn> just redirect stderr to /dev/null, but I don't use ksh
    Shawn> interactively.

    Shawn> Shawn

I guess my question was not precise enough.  I am not worrying about
seeing stderr, I am only concerned about stdout.

Here is an example (using GNU find, which takes pwd as the default
path):

---- Start of included text -----------------------8<--- cut here -------------


total 9
lrwxrwxrwx   1 petersen        4 Sep 10 10:55 link -> file
-rw-r--r--   1 petersen     4901 Sep  2 13:49 new-exp.sep
-rw-r--r--   1 petersen     2776 Sep  5 12:48 new-exp.txt
-rw-r--r--   1 petersen       52 Sep 11 13:44 output
lrwxrwxrwx   1 petersen       18 Sep 10 11:56 tmp -> /home/petersen/tmp/

.
./tmp
./output
./link
./new-exp.txt
./new-exp.sep
---- End of included text -------------------------8<--- and here -------------


The command

    find -follow

does better:

---- Start of included text -----------------------8<--- cut here -------------

.
./tmp
./tmp/fsf-copyright
./tmp/fsf-copyright.ps
./tmp/fsf-copyright~
./tmp/970616B.txt
./output
find: ./link: No such file or directory
./new-exp.txt
./new-exp.sep
---- End of included text -------------------------8<--- and here -------------


stderr), but unfortunately it deferences (lists) the symbolic link

I want the behaviour of -follow, without the deferencing of symlinks.

Thanks, Jens

 
 
 

how to have "find" not list bad symbolic links?

Post by Floyd Davids » Fri, 12 Sep 1997 04:00:00



>>> I want to ask: is it possible to get `find' to list everything
>>> except bad symbolic links (ie symlinks that point to nothing)?
...
>I guess my question was not precise enough.  I am not worrying about
>seeing stderr, I am only concerned about stdout.
...

>.
>./tmp
>./output
>./link
>./new-exp.txt
>./new-exp.sep
...


...

>.
>./tmp
>./tmp/fsf-copyright
>./tmp/fsf-copyright.ps
>./tmp/fsf-copyright~
>./tmp/970616B.txt
>./output
>find: ./link: No such file or directory
>./new-exp.txt
>./new-exp.sep
...

>stderr), but unfortunately it deferences (lists) the symbolic link

>I want the behaviour of -follow, without the deferencing of symlinks.

Add the option "-maxdepth 1" to limit the depth it will dereference
the sym link.  Then if you want to get rid of the eror message you
can redirect stderr to /dev/null to generally rid yourself of all
error messages, or more selectively do so by piping the output
through grep:  

  find -maxdepth 1 -follow 2>/dev/null
  find -maxdepth 1 -follow 2>&1 | grep -v "No such file or directory"

Floyd

--
     Floyd L. Davidson                           Salcha, Alaska

 
 
 

how to have "find" not list bad symbolic links?

Post by Andreas Schw » Sat, 13 Sep 1997 04:00:00



|> I want the behaviour of -follow, without the deferencing of symlinks.

Use `find ! -xtype l'.
--
Andreas Schwab                                      "And now for something

 
 
 

how to have "find" not list bad symbolic links?

Post by Randal Schwart » Sun, 14 Sep 1997 04:00:00


Jens-Ulrik> I want to ask: is it possible to get `find' to list
Jens-Ulrik> everything except bad symbolic links (ie symlinks that
Jens-Ulrik> point to nothing)?

Not find, but find2perl (installed alongside perl in most modern
systems):

    find2perl /where/ever -eval '-l and not -e' -ls | perl

find2perl rules!

Just another Perl hacker,

--
Name: Randal L. Schwartz / Stonehenge Consulting Services (503)777-0095
Keywords: Perl training, UNIX[tm] consulting, video production, skiing, flying

Web: <A HREF="http://www.stonehenge.com/merlyn/">My Home Page!</A>
Quote: "I'm telling you, if I could have five lines in my .sig, I would!" -- me

 
 
 

how to have "find" not list bad symbolic links?

Post by lvir.. » Wed, 17 Sep 1997 04:00:00


I can't quite make out from Solaris 2.5.1's find(1) man page how the -perm
flag is supposed to work.

If I want to find out what directories under a particular sub tree do _not_
have the set groupid sticky bit turned on, regardless of the other permission
modes, what value do I give find?
--

<URL:http://www.teraform.com/%7Elvirden/> <*> O- "We are all Kosh."
Unless explicitly stated to the contrary, nothing in this posting should
be construed as representing my employer's opinions.

 
 
 

how to have "find" not list bad symbolic links?

Post by Brian McCaule » Sun, 21 Sep 1997 04:00:00



> If I want to find out what directories under a particular sub tree do _not_
> have the set groupid sticky bit turned on, regardless of the other permission
> modes, what value do I give find?

Was that supposed to read "the set group id bit" or "the sticky bit"
or "either the set group id bit or the sticky bit" ?

For the setgid bit:

find -not -perm +2000

For "either the set group id bit or the sticky bit":

find -not -perm +3000

--

 .  _\\__[oo       from       | Phones: +44 121 471 3789 (home)

.  l___\\    /~~) /~~[  /   [ | PGP-fp: D7 03 2A 4B D8 3A 05 37...
 # ll  l\\  ~~~~ ~   ~ ~    ~ | http://wcl-l.bham.ac.uk/~bam/