LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 08-31-2021, 07:27 PM   #1
BudiKusasi
Member
 
Registered: Apr 2017
Distribution: Artix
Posts: 345

Rep: Reputation: 15
find util to distinguish the link result between link to file and lto directory


How can we have in Linux find util to distinguish the link result between link to file and link to directory ?
I tried find by using as explained
Code:
The -H, -L and -P options control the treatment of symbolic links.  Command-line arguments fol‐
   lowing these are taken to be names of files or directories to be examined, up to the first  ar‐
   gument that begins with `-', or the argument `(' or `!'.  That argument and any following argu‐
   ments are taken to be the expression describing what is to be searched for.  If  no  paths  are
   given, the current directory is used.  If no expression is given, the expression -print is used
   (but you should probably consider using -print0 instead, anyway).

   This manual page talks about `options' within the expression list.  These options  control  the
   behaviour  of find but are specified immediately after the last path name.  The five `real' op‐
   tions -H, -L, -P, -D and -O must appear before the first path name, if at all.  A  double  dash
   --  can  also  be  used to signal that any remaining arguments are not options (though ensuring
   that all start points begin with either `./' or `/' is generally safer if you use wildcards  in
   the list of start points).

   -P     Never  follow  symbolic  links.   This  is the default behaviour.  When find examines or
          prints information a file, and the file is a symbolic link, the information  used  shall
          be taken from the properties of the symbolic link itself.

   -L     Follow symbolic links.

  -H     Do  not follow symbolic links, except while processing the command line arguments.  When
              find examines or prints information about files, the information  used  shall  be  taken
              from  the  properties of the symbolic link itself
but didn't get the solution
Please help out. Thanks

Last edited by BudiKusasi; 08-31-2021 at 07:45 PM.
 
Old 08-31-2021, 07:56 PM   #2
astrogeek
Moderator
 
Registered: Oct 2008
Distribution: Slackware [64]-X.{0|1|2|37|-current} ::12<=X<=15, FreeBSD_12{.0|.1}
Posts: 6,269
Blog Entries: 24

Rep: Reputation: 4196Reputation: 4196Reputation: 4196Reputation: 4196Reputation: 4196Reputation: 4196Reputation: 4196Reputation: 4196Reputation: 4196Reputation: 4196Reputation: 4196
Have you read the reference for the -L option that you did not paste? From man find:

Code:
       -L     Follow  symbolic  links.   When find examines or prints information about files, the information used
              shall be taken from the properties of the file to which the link points, not  from  the  link  itself
              (unless it is a broken symbolic link or find is unable to examine the file to which the link points).
              Use of this option implies -noleaf.  If you later use the -P option, -noleaf will still be in effect.
              If -L is in effect and find discovers a symbolic link to a subdirectory during its search, the subdi‐
              rectory pointed to by the symbolic link will be searched.

              When the -L option is in effect, the -type predicate will always match against the type of  the  file
              that  a  symbolic  link  points  to rather than the link itself (unless the symbolic link is broken).
              Using -L causes the -lname and -ilname predicates always to return false.

Last edited by astrogeek; 08-31-2021 at 07:58 PM.
 
Old 08-31-2021, 07:59 PM   #3
PurpleSquirrel
LQ Newbie
 
Registered: Aug 2021
Location: Here
Distribution: Slackware 2.3 to post-15.0 current
Posts: 25

Rep: Reputation: 16
I think you're looking for "xtype" as a test. You would call find as "find -L /some/dir/ -xtype l -type d" then do as you like with the result. The option "-L" and the test string "-xtype l -type d" finds all the symbolic links and follows them (because of the "-L") then looks to see if the object the link is pointing at is a directory or not. There is some discussion of this in the man page for find.

HTH
 
1 members found this post helpful.
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Are the programs in util-linux the same version as those in util-linux-ng? harryhaller Slackware - Installation 2 10-07-2011 09:43 AM
[SOLVED] how to distinguish between tab and space in a file akhand jyoti Linux - Newbie 3 03-22-2011 02:12 AM
Distinguish between gdbm 64b to gdbm 32b in rpm spec file. byaron Red Hat 1 10-13-2010 06:35 PM
[SOLVED] how to distinguish between a original file and a hard link bzlaskar Linux - Newbie 2 12-11-2007 08:58 AM
how to distinguish a file and a directory joeyBig Programming 2 10-01-2004 04:21 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 10:48 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration