Find cmd and sym links


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users Find cmd and sym links
# 1  
Old 05-07-2017
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
Code:
find -L /u04 -name example.file -type f

Many thanks

Last edited by user052009; 05-07-2017 at 08:36 PM..
# 2  
Old 05-07-2017
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:
Quote:
LN(1) User Commands LN(1)

NAME
ln - make links between files

SYNOPSIS
ln [OPTION]... [-T] TARGET LINK_NAME (1st form)
ln [OPTION]... TARGET (2nd form)
ln [OPTION]... TARGET... DIRECTORY (3rd form)
ln [OPTION]... -t DIRECTORY TARGET... (4th form)

DESCRIPTION
In the 1st form, create a link to TARGET with the name LINK_NAME. In
the 2nd form, create a link to TARGET in the current directory. In the
3rd and 4th forms, create links to each TARGET in DIRECTORY. Create
hard links by default, symbolic links with --symbolic. By default,
each destination (name of new link) should not already exist. When
creating hard links, each TARGET must exist. Symbolic links can hold
arbitrary text; if later resolved, a relative link is interpreted in
relation to its parent directory.

Be careful doing this - lots of hard links use up the inode quota for the file system. Bad things happen at that point.
# 3  
Old 05-08-2017
Sure that works across file systems?
Quote:
Originally Posted by general_franco
. . . from a directory on one filesystem to that on another . . .
# 4  
Old 05-08-2017
If the start directory /u04 is a symlink then find -H /u04 ... will follow it, but not other symlinks.
# 5  
Old 05-08-2017
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 ----------

Quote:
Originally Posted by MadeInGermany
If the start directory /u04 is a symlink then find -H /u04 ... will follow it, but not other symlinks.
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 ----------

Quote:
Originally Posted by RudiC
Sure that works across file systems?
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.
# 6  
Old 05-08-2017
Quote:
Originally Posted by jim mcnamara
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.
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:
Code:
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:
Code:
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.
These 3 Users Gave Thanks to Don Cragun For This Post:
# 7  
Old 05-08-2017
Don -

Thanks for pointing that out. I was wrong. Don't know what I was thinking....
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Create Sym Links for a series of files

Hello, I would like to create symbolic links for a series of files in my cwd (after confirming that the links don't already exist). The above files all have a similar prefix, but different extensions. I created a shell script like shown below and I get an error message "No such file or... (4 Replies)
Discussion started by: Gussifinknottle
4 Replies

2. UNIX for Dummies Questions & Answers

Help with the find cmd

Hello, I'm having a trouble with the find cmd. I would like to find all the java versions on my systems. I have solaris 9 & 10 RHEL and SUSIE. java -version doesn't give all the versions on the server. So I am trying to use the find command to find them all find / -name java I would... (7 Replies)
Discussion started by: bitlord
7 Replies

3. Solaris

Hard Links and Soft or Sym links

When loooking at files in a directory using ls, how can I tell if I have a hard link or soft link? (11 Replies)
Discussion started by: Harleyrci
11 Replies

4. Shell Programming and Scripting

Nested find cmd

Hi gurus, greetings. Objective: find in a path directories that are named Logs. In each found Logs dir search for files with .log extension and remove -atime +6. (Note for test/example, rm and -atime is not used). Issue: If I execute the script without redirecting output to a file, on... (8 Replies)
Discussion started by: rsheikh
8 Replies

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

6. Shell Programming and Scripting

date with find cmd

Hi for today i have 10 files, in that i need search some values how can i write a find cmd with perticular date thanks SAIC (4 Replies)
Discussion started by: saic
4 Replies

7. Shell Programming and Scripting

Find cmd not working correctly in script

I am trying to copy 2 types of files so I can archive them. I tested with a set of commands: touch -t $(date -d "-60 day" +%Y%m%d) WORKDIR/REF find TARGETDIR/ -type f -maxdepth 1 -iname \*.out\* -or -iname \*.log\* ! -newer WORKDIR/REF -exec ls -l {} \; This correctly lists any files in the... (2 Replies)
Discussion started by: prismtx
2 Replies

8. Shell Programming and Scripting

using find cmd to find certain files

i have a list of files below: rwxrwxrwx 1 pipe pipe 180 Mar 4 22:47 del_0n_Date -rwxrwxrwx 1 pipe pipe 472 Mar 4 22:58 mail_Check -rw-r--r-- 1 pipe pipe 92 Mar 4 22:58 minfo.txt -rwxrwxrwx 1 pipe pipe 609 Mar 5 05:12... (6 Replies)
Discussion started by: ali560045
6 Replies

9. Shell Programming and Scripting

Find cmd not working as expected

Hi, i wan to search the file starting with Admin into the directory Output. I am running below command: find /appl/Output -name "Admin*" -prune but this command is going into the sub directories present under output. I do not want to search under sub directories. Any help will be highly... (6 Replies)
Discussion started by: Vishal123
6 Replies

10. UNIX for Dummies Questions & Answers

find and sym links

Would I be correct in assuming that find doesn't bother recursivley searching down sim links. (It doesn't seem to so I guess it doesn't!!!) Is there anyway to make it do so? (3 Replies)
Discussion started by: peter.herlihy
3 Replies
Login or Register to Ask a Question