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.
Notices
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.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Someone in my family has deleted a file (by "mv crap important") and is not in the best of moods, to say the least. I tried to "recover" it (its ext3), but it doesnt seem to pick up any deleted inodes. When a file is "mv"ed is it unlinked differently - is there any way to recover it?
thx for any quick responses.
Last edited by cuckoopint; 02-21-2003 at 05:35 AM.
sry, about that. I guess I was unclear. both crap and important were files not directories - so, it doesnt "move it", but "replace it" (or hence, delete the original)
UPDATE:
the situation iss under control, we found an old backup of it...close call.
I'd still like to know if there is a difference in the way mv unlinks nodes and rm unlinks them. And how could one recover from a "mv" - I dont think rewritten nodes were a problem in this case, since I was informed of the situation rather quickly.
mv moves files, so it should just be somewhere else. As for un-deleting things... that is tricky, if not impossible, in Linux. (I recently read something about searching your journal files for bits of text content, to see if the file is still floating around in there, but no guarantees).
If you remember the name of it, you can see if you can figure out where it got moved to. As whichever user moved the file, try:
I do believe that a mv is equivalent to a cp, and then a rm, for several observational reasons. First, if I attempt to mv a directory tree for which I have read, but not write permission, the files are copied, and then an error occurs during the unlink process. Second, on AIX (which, no is not Linux) a mv results in first cp showing up in top, and then an rm (in addition to an mv at lower usage), indicating that the process is explicitly that. I guess the definitive answer would be to compare the source on your implementation for cp, rm, and mv.
Originally posted by fsbooks I do believe that a mv is equivalent to a cp, and then a rm, for several observational reasons. First, if I attempt to mv a directory tree for which I have read, but not write permission, the files are copied, and then an error occurs during the unlink process. Second, on AIX (which, no is not Linux) a mv results in first cp showing up in top, and then an rm (in addition to an mv at lower usage), indicating that the process is explicitly that. I guess the definitive answer would be to compare the source on your implementation for cp, rm, and mv.
It all depends if the source and destination are on the same filesystem or not. A move between 2 filesystems are like a copy; rm. On the other hand, a move within the same filesystem is just a rename. The data stays where it is.
Distribution: openSUSE, Raspbian, Slackware. Previous: MacOS, Red Hat, Coherent, Consensys SVR4.2, Tru64, Solaris
Posts: 2,803
Rep:
This sounds like a case for setting up some aliases for those unwary users:
alias mv='mv -i'
alias rm='rm -i'
etc.
At least they have to stop and think (hopefully) when they see that prompt. And if that's not enough, show 'em to write protect the files: chmod -w important.stuff. And when you've finished with that lesson, develop that backup strategy. :-)
Originally posted by esm It all depends if the source and destination are on the same filesystem or not. A move between 2 filesystems are like a copy; rm. On the other hand, a move within the same filesystem is just a rename. The data stays where it is.
sorry for being confused... I understand its only a rename. but if the destination already exists, then the src overwrites the destination. correct? then how would one retrive the original dest. file after there was no name to refer it to. the way I see it:
I dont know about order, but it sounds like:
if dest==1; rm dest
cp src dest;
rm src;
so mv does not remove the old dest (if one exists). It just writes over it...correct?
this was my original question....I just wanted to know if it gets written over, or if it unlinks the old destination (and then if one's lucky, one can retrieve it)?
oh well...now that I think about it, a "written over" would make more sense. If so, thanks for the ideas guys. but I guess it's gone....
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.