Operating System - HP-UX
1832986 Members
2543 Online
110048 Solutions
New Discussion

Re: Help with find syntax

 
SOLVED
Go to solution

Help with find syntax

Hi,

While I was out on vacation several problems developed with our N4000 running 11i. I think my temporary replacement is to blame. A number of applications are failing with "file not found" and I think I have found the problem. A number of symbolic links refer to files that are missing. I've been trying to write a script using find. Basically, I'm doing this:
find /user /work -type l -exec ls -l {} \; > /tmp/filelist
That is finding the symbolic links but I am having trouble dealing with the absolute pathnames and relative pathnames. Is there another find option that will help?

Thanks,
Steve
6 REPLIES 6
Sridhar Bhaskarla
Honored Contributor

Re: Help with find syntax

Hi Steve,

Would the following work for you?

find /tmp -type l |xargs ll -d

This way ls -l doesn't traverse the sub directories and it will work for files too.

-Sri
You may be disappointed if you fail, but you are doomed if you don't try
A. Clay Stephenson
Acclaimed Contributor
Solution

Re: Help with find syntax

My psychic, Miss Cleo, tells me that your temp was an adoptee from another OS, possibly Micro... --- Miss Cleo said the remaining letters were fuzzy.

Well, I will give you a find hint. Use Perl's File::Find. It keeps up with the current directory and you can do your own thing inside the 'wanted' subroutine.

The problem with trying to parse ls -l
is the "xxx -> yyy" at the end of each ls -l output line. Separating the -> part from everything else is pretty simple BUT if the filenames have whitespaces (and they could) then things get very tricky. That still does not address the relative/absolute path problems.


I recently wriote a Perl script that was very close to your needs. Give me a few minutes and I'll modify it.

If it ain't broke, I can fix that.
Sridhar Bhaskarla
Honored Contributor

Re: Help with find syntax

Hi Steve,

I completely misunderstood (rather misread) your question.

May be one solution is to make use of 'basename' and|or 'dirname' commands to get what you want. For ex., if the link is like

/dir1/dir2/file -> file2

you can get the dir name of the first file with 'dirname /dir1/dir2/file'. basename will skip the directory tree and give you only the file name. A combination of both may work for you.

-Sri
You may be disappointed if you fail, but you are doomed if you don't try
A. Clay Stephenson
Acclaimed Contributor

Re: Help with find syntax

Here you go Steve. I had a script that was very close from this thread:
http://forums1.itrc.hp.com/service/forums/questionanswer.do?threadId=470847

Although I didn't have to use it, Perl has the readlink() function just like the readlink() system call and the lstat() function as well. It took me longer to modify the Usage() message than it did to modify the "meat" of the code.

Use it like this:
badslink.pl /home /usr
or
badslink.pl
The latter case will descend starting at the CWD. Invoke as badslink.pl -u for full usage.


If it ain't broke, I can fix that.

Re: Help with find syntax

Thanks. The Perl script worked. I found out what really happened. After talking to the other administrator, I found out that a directory had disappeared. He then did a restore from backup. The problem was that this was a mounted filesystem and he restored to the root filesystem. He filled up root during the restore and had to remove some files. I have now remounted the filesystem and all the files are back.

My question now is what happens when I mount a filesystem under a directory that already has files in it?

BTW, he is a Windows guy.

Thanks,
Steve
A. Clay Stephenson
Acclaimed Contributor

Re: Help with find syntax

If I understand your question, the answer is nothing. The files under the mountpoint "disappear" and are replaced by those in the mounted filesystem. When you umount the filesystem, the original files "reappear". You are, of course, wasting space in /. Moreover, it sounds as though what I would technically refer to as a "mess". Your newer data (as much of it as there is) are on / and your older, intact, data are on the mounted filesystem. You may have to "merge" these to get a good data set or re-enter data since the time of the filesystems disappearance. You might think about unount the filesystem and remounting under another mountpoint so that you could see both sets of data. When you finally clean this up, you should clean up everything below the mountpoint on /.
If it ain't broke, I can fix that.