Solved

Find all files with the same INODE ?

Posted on 2007-11-26
20
1,577 Views
Last Modified: 2013-12-26
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.
0
Comment
Question by:pillmill
  • 9
  • 6
  • 5
20 Comments
 
LVL 40

Expert Comment

by:omarfarid
ID: 20354529
Hi,

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
0
 
LVL 48

Expert Comment

by:Tintin
ID: 20354569
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

0
 

Author Comment

by:pillmill
ID: 20361682
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.
0
 
LVL 48

Expert Comment

by:Tintin
ID: 20362213
pillmill.

What system are you on where

find -type f -links +1

lists symbolic links?

Certainly doesn't under Solaris and Linux.
0
 
LVL 40

Expert Comment

by:omarfarid
ID: 20362474
Hi,

pillmill:

Did you try the command I gave?

0
 

Author Comment

by:pillmill
ID: 20362597
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.
0
 
LVL 40

Expert Comment

by:omarfarid
ID: 20362842
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
0
 
LVL 48

Expert Comment

by:Tintin
ID: 20363487
>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.
0
 
LVL 48

Expert Comment

by:Tintin
ID: 20363495
omarfarid, your last code sample is not recursive or csh.



0
 
LVL 40

Expert Comment

by:omarfarid
ID: 20363515
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.



0
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 
LVL 48

Expert Comment

by:Tintin
ID: 20363715
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)"
0
 
LVL 40

Expert Comment

by:omarfarid
ID: 20363747
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.

0
 
LVL 48

Expert Comment

by:Tintin
ID: 20363888
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
0
 

Author Comment

by:pillmill
ID: 20376664
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

0
 
LVL 40

Expert Comment

by:omarfarid
ID: 20376700
Hi,

pillmill:

If you add -mount do you still get 7 files?

0
 
LVL 48

Expert Comment

by:Tintin
ID: 20377163
Could you please post the output of

find /dir -name file1.cpp -exec ls -li () \;
0
 

Author Comment

by:pillmill
ID: 20377840
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
0
 
LVL 48

Expert Comment

by:Tintin
ID: 20379187
Hmm, very strange.  Are any of those directories listed in separate filesystems or on NFS mounted directories?
0
 

Author Comment

by:pillmill
ID: 20384366
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.
0
 
LVL 48

Accepted Solution

by:
Tintin earned 500 total points
ID: 20392148
I can't think of any possible way you could have a file with 1 link and the same inode as multiple other files if they are on the same filesystem.  It defies the basic laws of Unix.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Many time we need to work with multiple files all together. If its windows system then we can use some GUI based editor to accomplish our task. But what if you are on putty or have only CLI(Command Line Interface) as an option to  edit your files. I…
In the distant past (last year) I hacked together a little toy that would allow a couple of Manager types to query, preview, and extract data from a number of MongoDB instances, to their tool of choice: Excel (http://dilbert.com/strips/comic/2007-08…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now