Operating System - HP-UX
1826605 Members
3283 Online
109695 Solutions
New Discussion

find command to find directories and sym links to directories

 
kenny chia
Regular Advisor

find command to find directories and sym links to directories

Hi
For HPUX how should I use the find command to look for
1) Directories
and
2) Symbolic links to directories. Sym links to files I do not want

In Linux I use
find ! -type f ! -xtype f
but xtype does not work in HPUX
All Your Bases Are Belong To Us!
11 REPLIES 11
Steven E. Protter
Exalted Contributor

Re: find command to find directories and sym links to directories

Shalom,

the man page is pretty helpful here.

find -type f
| xargs 555
Finds all files actually files permissions 555.

HP-UX man pages are actually a little better than Linux man pages, IMO

SEP
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
James R. Ferguson
Acclaimed Contributor

Re: find command to find directories and sym links to directories

Hi Kenny:

The standard HP-UX 'find' can easily be used for finding directories (question-1):

# find /path -type d -print

To find symbolic links to directories, but not symbolic links to files, I'd use Perl:

# perl -MFile::Find -MCwd=realpath -le 'find(sub{print $File::Find::name if -l $_ && -d realpath($_)},@ARGV)' /path

Regards!

...JRF...
Dennis Handly
Acclaimed Contributor

Re: find command to find directories and sym links to directories

>1) Directories

find path -type d

>2) Symbolic links to directories.

This requires two steps in the shell:
find path -type l -exec check_sym_link +

Then write the check_sym_link script:

for file in "$@"; do
ll -Ld $file | grep -q "^d" && echo $file
done

(I'm not sure if [ -d $file ] would work too?)

>SEP: find -type f | xargs 555

You mean:
find -type f -perm 555 ?
Steven Schweda
Honored Contributor

Re: find command to find directories and sym links to directories

> In Linux I use
> find ! -type f ! -xtype f
> but xtype does not work in HPUX

If you really like the "find" in GNU/Linux,
you could try (building and) using that
"find" on HP-UX. The source code is
available:

http://www.gnu.org/software/findutils/
Deepak Kr
Respected Contributor

Re: find command to find directories and sym links to directories

For DIR

find /path -type d -name " " ...

For Link

find /path -type l -name " " ....

HP-UX find is equally stronger!!!

"There is always some scope for improvement"
Steven Schweda
Honored Contributor

Re: find command to find directories and sym links to directories

> For Link
>
> find /path -type l -name " " ....

I must be missing something. Can you
demonstrate that this works? (Why
'-name " " ....'? What's "...."?)

> 2) Symbolic links to directories. Sym
> links to files I do not want

You did read this, right?
Dennis Handly
Acclaimed Contributor

Re: find command to find directories and sym links to directories

>Kumar Deepak: HP-UX find is equally stronger!

You are confusing "stronger" with the saying: standard is better than better. :-)
Dennis Handly
Acclaimed Contributor

Re: find command to find directories and sym links to directories

>ME: (I'm not sure if [ -d $file ] would work too?)

Yes that works:
for file in "$@"; do
[ -d "$file" ] && echo "$file"
done
kenny chia
Regular Advisor

Re: find command to find directories and sym links to directories

Hi all
I manage to find a single line solution

# find -type l -o -type d | perl -e 'while(){chomp();print "$_\n" if -d;}'
All Your Bases Are Belong To Us!
Rasheed Tamton
Honored Contributor

Re: find command to find directories and sym links to directories

Hi,

find /var/tmp -follow -type d -exec ll -d {} +|grep ^l

Rgds.
Dennis Handly
Acclaimed Contributor

Re: find command to find directories and sym links to directories

>Rasheed: find /var/tmp -follow -type d -exec ll -d {} + | grep ^l

Clever. Except if the symlink points to some gigantic directory tree that you don't want to scan, you'll waste time there.