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.
[SOLVED] BASH: finding if two files are on the same device
I have a bash script that deals with copying very large (>4GB) files from one folder to another. To prevent loss of data I copy the file, check that the file sizes are equal, and then remove the old one. I'm looking for a way to determine when two files in different directories are on the same device so that I can merely rename the file. There most definitely will be cases of cross-device symlinking (shown in the example below) which prevents me from using something like `dirname`. I'll result to parsing a mount listing if there is no simple command(s) to resolve a file to its device.
It would appear the two files are both on /dev/hda1 but in fact the old one is on /dev/hda2 and the new one is on /dev/hdb1. This is just a simple example to show my problem and in no way represents the actual directory structure (which is more complicated).
Last edited by JakeWharton; 06-28-2008 at 12:03 AM.
Reason: Problem was solved
I may be misundersanding your problem, sorry if so, but the mv command will rename a file, including moving it from one directory to another, for directories on the same partition/filesystem, and will make a copy if the move is to a different filesystem. It does some error checking and will not erase the original if the copy is unsuccessful. It also has some backup options you may find useful.
The mv command indeed is atomic this way, but it is important to note that neither mv nor the OPs size comparison guarantees identical copies. If fidelity is critical, then perform checksums on the files and compare those as well. Unfortunately, mv makes this impossible, as once the copy (to a new file system) is complete, the original is unlinked.
So, for critical data, where the is the possibility of error, a copy/checksum/unlink operation is best.