find - link - error


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers find - link - error
# 1  
Old 01-21-2010
find - link - error

Have a random question:

In simple terms I have a find command on a dir:

/path/user/data/

/path/user is a link to:

/tmp/storage/


The find command outputs the files it finds as:

/path/user/data/file

What I need is:

/tmp/storage/file

Is there a way to "resolve" the Unix (Aix) file to its true location? Have tried numerous find options but to no avail.
# 2  
Old 01-21-2010
the explanation is clear though, what is the find command you used ?
# 3  
Old 01-21-2010
The original command is:

Code:
find ${DATAENV}/raw/archive/storage -mtime +4 -type fd

The ${DATAENV}/raw is the linked area. so find can't tell that the levels preceeding are links.

I tried with the -H and -L and -follow -xdev etc all seem to do nothing and indicate that find thinks its on the /tmp/storage/.... area from the start.

The only way I can see around this is to do some sort of pre-check:

Code:
NEWPATH=$(ls -l ${UKDWENV} | grep raw | sed 's/.*\-> //g')

and then use ${NEWPATH} in the find.

Just seems like there should be a command like ls / other to disclose a files true location.
# 4  
Old 01-21-2010
I don't have a simple solution but on my system /usr/bin/pwd gives the real location of a directory as distinct from the shell builtin pwd.
# 5  
Old 01-21-2010
find + readlink does the trick.
Here is my example setup:
Quote:
> ls -Rl
total 0
drwxr-xr-x 3 user group 102 Jan 21 21:01 dir_1/
drwxr-xr-x 3 user group 102 Jan 21 21:02 dir_2/

./dir_1:
total 0
-rw-r--r-- 1 user group 0 Jan 21 21:01 file_1

./dir_2:
total 8
lrwxr-xr-x 1 user group 12 Jan 21 21:02 file_1 -> dir_1/file_1
If you can afford to run two commands, then do
Code:
> find . \! -type l -print
.
./dir_1
./dir_1/file_1
./dir_2

> find . -type l -exec readlink {} \;
dir_1/file_1

If you need to have it in one command, try
Code:
> find . \( \! -type l -print \) -or \( -type l -exec readlink {} \; \)
.
./dir_1
./dir_1/file_1
./dir_2
dir_1/file_1

which derives from
Code:
> find . \( \! -type l -print \) -or \( -type l -print \)
.
./dir_1
./dir_1/file_1
./dir_2
./dir_2/file_1

Note that readlink removes the './' - but that should not hurt usually. In case it does: normalize all results, and re-add it to all of them...
# 6  
Old 01-22-2010
@Andre_Merzky @Methyl
Thanks for the replies, think both would work if I was searching in the directory above. The issue is its a linked directory and I am searching lower down the path i.e:

${DATAENV}/raw/archive/storage

Where the raw directory is a linked one. So any files found in storage find see's as real files. Don't think what I need, with the restrictions I have has a solution (at least not a simple / one liner :-( ).

Think its going to be a re-write of the script and calling scripts to pass in a new path to the real files.

Thanks for your replies.

---------- Post updated at 04:49 AM ---------- Previous update was at 04:24 AM ----------

Came up with this solution:

Code:
find ${DATAENV}/raw/archive/storage -mtime +4 -type fd | head -1 | 
awk -v DEF=${DATAENV} -v q=\' ' { 
print "echo " $0 " | sed \"s?" DEF "?`df -g " $0 " | awk " q " { print $7 } " q " | tail -1`?g\" " 
} ' | ksh | other-commands-here

Phew.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

AIX - find also in symbolic link

Hi, i tried to search a string, recursively, in subdirectories with: find . -type f -print | xargs grep -s hello i found all files that contain the string "hello" but i would perform a search also in symbolic link, so i tried with find -L . -print | xargs grep -s hello but no result was... (3 Replies)
Discussion started by: nash83
3 Replies

2. Shell Programming and Scripting

wanted to find both link file and ordinary file using single find command

find . -type fl o/p is only the ordinary file. where in it wont give the link files. (2 Replies)
Discussion started by: nikhil jain
2 Replies

3. Shell Programming and Scripting

How to bin/find w/ -follow without searching both link and target

I am interested in searching links to files not found within a directory, so I use the -follow option. However, the dir may contain links to files that are also found within the dir. That means if I bin/find a bunch of files then search their contents using grep, I get redundant information. An... (1 Reply)
Discussion started by: stevensw
1 Replies

4. Solaris

Not able to find the link for downloading

Hi, Please let me know the link for downloading gcc.c2.95.3-p5 of Solaris 10. Thanks in advance. (3 Replies)
Discussion started by: dudala
3 Replies

5. Shell Programming and Scripting

Find and symbolic link modification time

Hi, I have a directory made up of many symbolic links to folders multiple file systems. I want to return folders modified within the last 50 days, but find is using the link time rather than the target time. find . -type d -mtime -50 Is there a way to either: a) Make a symbolic link... (1 Reply)
Discussion started by: earls
1 Replies

6. Shell Programming and Scripting

Find Hard Link

Goodmorning everybody. A question: How can i match if a file is an hard link or not? (6 Replies)
Discussion started by: Guccio
6 Replies

7. Shell Programming and Scripting

How to find link files

How to find the link files. i have main file, now i want to find all the files linked to it. (4 Replies)
Discussion started by: aju_kup
4 Replies

8. UNIX for Dummies Questions & Answers

How to find .dat file in symbolic link

Hi, I am trying to find all files in a directory that have .dat and .int extensions and removing them. rm -f `find ${MY_DIR} -type f -name '*.dat' -o -name '*.int'` This works fine if $MY_DIR is a regular directory. However when $MY_DIR is a symbolic link then this command fails. How... (1 Reply)
Discussion started by: neeto
1 Replies

9. Shell Programming and Scripting

How to link lsof and find cmd?

Hi All, My target is to find the biggest files opened by any process and from that i have to find process id and the corresponding file also to avoid file system being hung-up. Finding the process id: is to kill the process Finding the biggest file: is to remove the file To get the process... (0 Replies)
Discussion started by: Arunprasad
0 Replies

10. Shell Programming and Scripting

how find the link of the file

Hi, I have a flat file which is used by a program. I dont know the program name .This file is in used by that program which is still running ? Is there any way to find out which program is accessing this file just by knowing the file name? Can we check some thing in "ps" just by knowing only... (8 Replies)
Discussion started by: Manish Jha
8 Replies
Login or Register to Ask a Question