Find cmd and sym links

Hi. Can somebody tell me if there's a way of creating a symbolic link from a directory on one filesystem to that on another that will allow a find command that doesn't use the -L param to locate a particular file under that new 'linked' dir. With a normal sym link the find command on that filesystem won't list the specified file ... unless I use

find -L /u04 -name example.file -type f 

Many thanks

If you create another (second) inode - not a symlink (a hard link) - then it will work.

Use the ln command -this has one limitation for the new hard link : the file has to be in the same file system as the original. That usually means the same mount point with no intervening mount points. From my man page:

Be careful doing this - lots of hard links use up the inode quota for the file system. Bad things happen at that point.

Sure that works across file systems?

If the start directory /u04 is a symlink then find -H /u04 ... will follow it, but not other symlinks.

Thanks Jim. Unfortunately I get the following error when trying to create a hard link:
Invalid cross-device link

---------- Post updated at 02:26 AM ---------- Previous update was at 02:24 AM ----------

Thanks also but the find cmd doesn't have a -L or a -H and I can't change the cmd in this instance so I need a work around with the link creation. Although none may be possible.

---------- Post updated at 02:30 AM ---------- Previous update was at 02:26 AM ----------

Yes it's just a normal ln -s link from a dir on one file system to that on another on the same host. A find cmd won't list any file under that link without an additional param like -L. Would just like to know if I can change the link in some way (rather than the find cmd) to get this to work. Thanks.

Hi Jim,
No. No matter how many hard links there are to a file, that file only consumes one i-node.

If you have a bunch of symbolic links pointing to a regular file, the regular file and each symlink will consume separate i-nodes; but even if there are a 1000 hard links (i.e., 1000 different directory entries naming a single file) to a file, that file only consumes one i-node.

Note that if you use the command:

ln sym link

where sym is the name of an existing file of type symbolic link, the standards do not specify whether the file named link will be created as a hard link to the symbolic link sym or as a hard link to the file to which sym resolves. (The latest revision of the POSIX standard added -L and -P options to the ln utility to let the user choose the behavior they want, but most implementations haven't released updates that conform to this version of the standard yet.)

Hi general_franco,
By definition, you can't hard link files that are on different filesystems.

When asking questions like this, it always helps to know what operating system you're using.

Have you tried:

find /u04/ -name example.file -type f

? Adding the trailing / to the pathname operand you pass to find will fail if that pathname argument doesn't resolve to a directory, but it should cause any symbolic links contained in that pathname to be resolved with or without the -L option.

3 Likes

Don -

Thanks for pointing that out. I was wrong. Don't know what I was thinking....