LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This 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


Reply
  Search this Thread
Old 02-20-2003, 09:11 PM   #1
cuckoopint
Member
 
Registered: Feb 2003
Distribution: Debian
Posts: 797

Rep: Reputation: 30
Unhappy mv vs. rm


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.
 
Old 02-20-2003, 09:13 PM   #2
loke137
Member
 
Registered: Feb 2003
Location: Brasil
Distribution: Debian Etch
Posts: 147

Rep: Reputation: 15
mv moves it right?? so it should be somewhere else, not deleted???
 
Old 02-20-2003, 09:21 PM   #3
esm
LQ Newbie
 
Registered: Feb 2003
Posts: 3

Rep: Reputation: 0
if in
# mv crap important

"important" was not an existing directory, you could type:

#mv important crap

and be back to square 1. If "important" was an existing directory, you should be able to recover with:

#mv important/crap .
including the dot ath the end.


of course you should change directory to where the file or directory was in the first place.

Hope this helps.
 
Old 02-20-2003, 09:33 PM   #4
cuckoopint
Member
 
Registered: Feb 2003
Distribution: Debian
Posts: 797

Original Poster
Rep: Reputation: 30
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.

Any one out there would like to shed some light?
 
Old 02-20-2003, 09:34 PM   #5
wapcaplet
LQ Guru
 
Registered: Feb 2003
Location: Colorado Springs, CO
Distribution: Gentoo
Posts: 2,018

Rep: Reputation: 48
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:

find / -name filename
 
Old 02-20-2003, 10:23 PM   #6
fsbooks
Member
 
Registered: Jan 2002
Location: Missoula. Montana, USA
Distribution: Slackware (various)
Posts: 464

Rep: Reputation: 52
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.
 
Old 02-20-2003, 10:38 PM   #7
esm
LQ Newbie
 
Registered: Feb 2003
Posts: 3

Rep: Reputation: 0
Quote:
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.

Just try

ls -i
before and after a mv and compare it to the

ls -i

before and after a copy..
 
Old 02-20-2003, 10:40 PM   #8
rnturn
Senior Member
 
Registered: Jan 2003
Location: Illinois (SW Chicago 'burbs)
Distribution: openSUSE, Raspbian, Slackware. Previous: MacOS, Red Hat, Coherent, Consensys SVR4.2, Tru64, Solaris
Posts: 2,803

Rep: Reputation: 550Reputation: 550Reputation: 550Reputation: 550Reputation: 550Reputation: 550
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. :-)
 
Old 02-21-2003, 02:37 AM   #9
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985
mod note: *NOTHING* is "urgent" here please.
 
Old 02-21-2003, 05:34 AM   #10
cuckoopint
Member
 
Registered: Feb 2003
Distribution: Debian
Posts: 797

Original Poster
Rep: Reputation: 30
Quote:
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;

am i completely off track?
 
Old 02-21-2003, 05:38 AM   #11
cuckoopint
Member
 
Registered: Feb 2003
Distribution: Debian
Posts: 797

Original Poster
Rep: Reputation: 30
good advice, rnturn. thx.

sry about that acid_kewpie. I guess I acted a little hastily. Just got caught up in the moment.
 
Old 02-21-2003, 05:40 AM   #12
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985
what do you mean retrieve? if you've over written a file then it's gone....
 
Old 02-21-2003, 05:57 AM   #13
cuckoopint
Member
 
Registered: Feb 2003
Distribution: Debian
Posts: 797

Original Poster
Rep: Reputation: 30
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....
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
boot sector and lilo collapse !!!!! URGENT URGENT URGEN !!!!! frelihm Linux - Software 21 12-02-2009 10:21 AM
Urgent Question Regarding Urgent Questions! Need Help Now! Crashed_Again LQ Suggestions & Feedback 11 10-17-2007 08:07 PM
urgent help please !!! deepdark SUSE / openSUSE 5 01-02-2005 11:39 PM
Urgent..Im Having A Nightmare..Urgent!!!! midgcool Linux - Software 41 11-30-2004 10:19 AM
Urgent Urgent !!!! Mozilla Keeps All Your Deleted Emails !!!! odin123 Linux - Software 2 01-31-2004 02:22 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 10:31 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration