Linux - GeneralThis Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Introduction to Linux - A Hands on Guide
This guide was created as an overview of the Linux Operating System, geared toward new users as an exploration tour and getting started guide, with exercises at the end of each chapter.
For more advanced trainees it can be a desktop reference, and a collection of the base knowledge needed to proceed with system and network administration. This book contains many real life examples derived from the author's experience as a Linux system and network administrator, trainer and consultant. They hope these examples will help you to get a better understanding of the Linux system and that you feel encouraged to try out things on your own.
Click Here to receive this Complete Guide absolutely free.
Is there any command to test if two files reside on the same file system? I would ideally like the test to dereference sylinks, so knowing they are in the same directory may not be enough.
I see that when I 'stat' a file, I am given a device identifier, but what if two files are on the same device (hard disk) but different partitions and thus different file-systems? Or do different partitions have different "device" numbers?
You see these things for Windows all the time. I had expected someone to create one for Linux by now.
Well, you could write a bash script to do this. If I wanted this I would write a bash script that would generate an MD5 sum for each file on the system. The sum and the name of its file would be put into a text file. When all of the files have been summed I would sort that file based on the sum, which would be the first element in each line. Then look for duplicates. Thinking about this reminded me of my college days.
I'm not sure I've been clear about what I'm trying to solve. I want to test if two files reside on the same filesystem. I shouldn't need to checksum my entire hard drive to see if a file is on the flash drive or CD.
You can see that the device identifier is different for each file. The same thing is true for soft links on different partitions.
Hard links have got to reside on the same partition/file system. Hard links are exactly the same as all other hard links pointing to the same file so they do not need to be dereferenced. The inode number will be the same in all hard links pointing to the same file.
Last edited by stress_junkie; 09-12-2007 at 08:23 PM.
"stat -t" should work - that device number (field 7) is a combined major/minor by the looks of it. 0xMMmm - where the leading zero gets dropped. Same device (hard disk) will have same major number - each partition will have a different minor number.
Simple check for equality should suffice.