pillmill
asked on
Find all files with the same INODE ?
How do I find all the file in a file system with that have the same INODE ?
I want a list of all the files that have the same INODE for all INODES in a
directory (and the sub-directories)
Thanks.
I want a list of all the files that have the same INODE for all INODES in a
directory (and the sub-directories)
Thanks.
Another way of phrasing your question is that you want to list all files in a directory that have hard links.
find /some/dir -type f -links +1
find /some/dir -type f -links +1
ASKER
find -type f -links +1 appears to list the files with SYMBOLIC links.
I want the files with HARD links.
Find -inum will generate a file with an identical INODE.
I want all the files in the directory system with the same INODE.
I want the files with HARD links.
Find -inum will generate a file with an identical INODE.
I want all the files in the directory system with the same INODE.
pillmill.
What system are you on where
find -type f -links +1
lists symbolic links?
Certainly doesn't under Solaris and Linux.
What system are you on where
find -type f -links +1
lists symbolic links?
Certainly doesn't under Solaris and Linux.
Hi,
pillmill:
Did you try the command I gave?
pillmill:
Did you try the command I gave?
ASKER
Tintin:
Sorry. It's just giving me more than I want.
Can I restrict the output of the number of links to
those within the directories I am searching ?
I just want a list of the files that have 2 or more
hard links within the directory structure.
I'm running Solaris, csh.
Sorry. It's just giving me more than I want.
Can I restrict the output of the number of links to
those within the directories I am searching ?
I just want a list of the files that have 2 or more
hard links within the directory structure.
I'm running Solaris, csh.
Hi,
Your aim is to find the files with 2 or more links, or you want to identify all files which are the same?
You may use the ls -l and check the 2nd field:
for file in `ls -l | awk ' { if ($2 > 1 ) { print $9 } }'`
do
if test -f $file
then
echo $file
fi
done
Here echo can be replaced with ant command like ls -l
Your aim is to find the files with 2 or more links, or you want to identify all files which are the same?
You may use the ls -l and check the 2nd field:
for file in `ls -l | awk ' { if ($2 > 1 ) { print $9 } }'`
do
if test -f $file
then
echo $file
fi
done
Here echo can be replaced with ant command like ls -l
>Can I restrict the output of the number of links to
>those within the directories I am searching ?
That's what the my find command does. Can you show an example of where this is not the case?
>I just want a list of the files that have 2 or more
>hard links within the directory structure.
And that's what my find command does.
>those within the directories I am searching ?
That's what the my find command does. Can you show an example of where this is not the case?
>I just want a list of the files that have 2 or more
>hard links within the directory structure.
And that's what my find command does.
omarfarid, your last code sample is not recursive or csh.
Hi,
Tintin:
Thank you for your comments, but is it required to provide solution in csh? I thought csh is not recommended :)
I could not understand why it should be recursive? I thought pillmill wants to restrict it to the same dir.
Tintin:
Thank you for your comments, but is it required to provide solution in csh? I thought csh is not recommended :)
I could not understand why it should be recursive? I thought pillmill wants to restrict it to the same dir.
The original question says:
"I want a list of all the files that have the same INODE for all INODES in a
directory (and the sub-directories)"
"I want a list of all the files that have the same INODE for all INODES in a
directory (and the sub-directories)"
Hi,
If the interest is to find files that have more than one hardlink, then find can do that.
But getting a list of files only is not enough to tell whaich filenames are pointing to the same file. The inode number should be used. Also, different files on different file systems can have same inode number and hence fid should be limited to the same filestsem with the -mount option.
If the interest is to find files that have more than one hardlink, then find can do that.
But getting a list of files only is not enough to tell whaich filenames are pointing to the same file. The inode number should be used. Also, different files on different file systems can have same inode number and hence fid should be limited to the same filestsem with the -mount option.
Probably safer to use -mount option. If you want to see what files are linked to what, then the following command will help
find /dir -type f -links +1 -mount -exec ls -i {} \; |sort -n
find /dir -type f -links +1 -mount -exec ls -i {} \; |sort -n
ASKER
Thanks Tintin:
The following give me different results:
1) find /dir -type f -links 1 -mount -exec ls -i {} \; |sort -n
produces files with one or more links. I want ONLY files that are DUPLICATED.
(Using a parameter of "2" or of "+1" generates NO files.
2) find /dir -name file1.cpp -exec ls -i () \;
produces SEVEN files, each in different directories, and each having the same Inode.
This is the list that I want.
In other words, there are SEVEN files called "file1.cpp" in the directory structure.
I need a way to extract ALL the other files having the SAME Inode NUMBERS.
Thanks
The following give me different results:
1) find /dir -type f -links 1 -mount -exec ls -i {} \; |sort -n
produces files with one or more links. I want ONLY files that are DUPLICATED.
(Using a parameter of "2" or of "+1" generates NO files.
2) find /dir -name file1.cpp -exec ls -i () \;
produces SEVEN files, each in different directories, and each having the same Inode.
This is the list that I want.
In other words, there are SEVEN files called "file1.cpp" in the directory structure.
I need a way to extract ALL the other files having the SAME Inode NUMBERS.
Thanks
Hi,
pillmill:
If you add -mount do you still get 7 files?
pillmill:
If you add -mount do you still get 7 files?
Could you please post the output of
find /dir -name file1.cpp -exec ls -li () \;
find /dir -name file1.cpp -exec ls -li () \;
ASKER
Here is the output. The first field is the Inode and it show seven files
with the same Inode number in this directory structure:
7239 -r--r--r-- 1 cc cd 35 Dec 9 2005 ./Pr/C/file01.h
7239 -r--r--r-- 1 cc cd 35 Dec 9 2005 ./P/D/file01.h
7239 -r--r--r-- 1 cc cd 35 Dec 9 2005 ./P/E/file01.h
7239 -r--r--r-- 1 cc cd 35 Dec 9 2005 ./P/H/file01.h
7239 -r--r--r-- 1 cc cd 35 Dec 9 2005 ./P/T/file01.h
7239 -r--r--r-- 1 cc cd 35 Dec 9 2005 ./U/ca/file01.h
7239 -r--r--r-- 1 cc cd 35 Dec 9 2005 ./U/ca/file01.h
with the same Inode number in this directory structure:
7239 -r--r--r-- 1 cc cd 35 Dec 9 2005 ./Pr/C/file01.h
7239 -r--r--r-- 1 cc cd 35 Dec 9 2005 ./P/D/file01.h
7239 -r--r--r-- 1 cc cd 35 Dec 9 2005 ./P/E/file01.h
7239 -r--r--r-- 1 cc cd 35 Dec 9 2005 ./P/H/file01.h
7239 -r--r--r-- 1 cc cd 35 Dec 9 2005 ./P/T/file01.h
7239 -r--r--r-- 1 cc cd 35 Dec 9 2005 ./U/ca/file01.h
7239 -r--r--r-- 1 cc cd 35 Dec 9 2005 ./U/ca/file01.h
Hmm, very strange. Are any of those directories listed in separate filesystems or on NFS mounted directories?
ASKER
Yes, I noticed that the links are all indicated as "1" and not as "7".
These files are drawn from a separate system that is managed
by ClearCase version control software. It looks like I will need to
write a script to get the output I want.
These files are drawn from a separate system that is managed
by ClearCase version control software. It looks like I will need to
write a script to get the output I want.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
The command ls -i will show the inode of a file. Also the find command with the -inum option will find files b inode number.
So if you know the inode number of a file you can use
find /dir -type f -inum number -mount
The number is the inode number of the file
the -mount option is to restrict search to the same filesystem since files on different filesystem can have the same inode number (hence are different files)
- type f is to list files only (directories will not have the same inode number)
For more info about find please see
http://unixhelp.ed.ac.uk/CGI/man-cgi?find