0

I have a log of files that's on a NFS, and they are connected via softlinks on the local redhat server.

When I try to run search for any files that was touched during last weekend and calculate their total sizes, I found that the results are wrong.

find . -mtime +3 -a -mtime -5 -ls

This gives me the names,paths,size,gid,uid,etc of the files that was touched within last weekend. That is great.

The problem comes with the softlinks. it is only reporting the links sizes itself, not the file that it is linking towards. So the link might only be 102 bytes while the actual file is 24G. Also it appears to be double counting somewhere because it is telling me that I have 23TB of files when the total storage size is 11TB.

Is there a way to get around this?

Thanks

1

Use the -L flag to follow symbolic links.

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 subdirectory 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.

0

readlink -f will gibe you the target of a symbolic link; you can then use stat on the output of reddlink to get get data on the actual file on disk. You can also use find -L to follow symlinks to their targets, and then then additionally | sort | uniq so as not to double-count files which are linked to within the specifications of your find predicate.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.