Extracting file information from Inode number
Hi All,
I was wondering if there is any way by which we can extract the file information from inode number, like permissions,ownership,mtime etc. Forexample if i have an inode number such as 4462, then how do i read this inode number to know what all information it has. |
you can use stat command but i dont think it shows information by inode number for input.
you can change inode number to file adress by using find command like this : Code:
# find -inum 1441793 -exec stat {} \; -exec = run command on files that matched. |
Try:
Code:
~$ find -inum 4462 -exec ls -la {} \; |
Perhaps debugfs is what you are thinking of:
http://superuser.com/questions/39010...-fsdb-in-linux It can examine any ext based filesystem and identify files by inode. Note: it is STRONGLY recommended that this only be used on a dismounted filesystem. It may even require that before it will run. |
Quote:
|
Quote:
|
Quote:
|
Quote:
Code:
# df /var Code:
# mount --bind / /mnt/tmp Code:
# rm -r /mnt/tmp/var/lib Code:
# umount /mnt/tmp |
I appreciate all your responses, but I think my question has been little misunderstood. I know how to find and see Inode number what i wanted to know is how i can know file information just by looking at the inode number. I mean i have reading this since i started learning linux that inode number contains 6-7 types of information it few to name like file permissions, information about file owner and when file was accessed/modified. So is it possible if i have a inode number and by just looking at it i can determine file infomation.
|
Inode number contains all info, including file type, size, location of the file, owner, group etc, except filename itself.
Therefore, in case, if you only need info. about file attributes, then ls cmd and it's associated options will do that. Code:
~$ ls -l filename OR, to find a file on basis of it's inode number, and display file attributes, use: Code:
~$ find -inum 4462 -exec ls -la {} \; |
Quote:
|
Quote:
Also you get file type using file cmd: Code:
~$ file <filename> |
I THINK the op wants something like an "openi", which opens a file by the inode number; or a "stati", which would retrieve metadata based on the inode number.
These don't exist in Linux, partly for security reasons, partly because they don't provide any real advantage. Security wise - it totally breaks GRS which only protects pathnames. It can also bypass user protection - if a user has 700 access mode on his home directory, but files within have 755 (happens a lot), then opening a file by inode bypasses the protection offered by the home directory. Usefulness - The only system I've seen these system calls was UNICOS... and they were specifically implemented to optimize NFS access. In UNICOS the nfsd services for file access ran in user mode, as the owner of the file (nfsd had additional multi-level security definitions that prevented that user from causing a DOS by aborting the daemons). Since NFS file access is via "handles" which didn't carry file names (a SLOW way to access a file to read a block) - these handles used an inode cached as part of the local handle. Using openi and stati was used to bypass the relatively slow namei lookup in the kernel. Sinc nfsd runs in user mode, it had no choice other than to have a special purpose system call for fast access. Linux has the NFS servers running in kernel mode to eliminate the DOS possibility. This also means the nfsd task has access to inode lookups without having to go through a namei lookup. So these calls don't provide any real benefit. |
All times are GMT -5. The time now is 10:45 PM. |