Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
What happens if mv is stopped mid execution?...
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Installing Gentoo
View previous topic :: View next topic  
Author Message
Budoka
l33t
l33t


Joined: 03 Jun 2012
Posts: 687
Location: Tokyo, Japan

PostPosted: Sun May 27, 2018 3:23 am    Post subject: What happens if mv is stopped mid execution?... Reply with quote

...AKA "type-o's and my stupidity never ceases to amaze me."

So I was trying to mv some files to a directory and the realized the output was copying a bunch of stuff I hadn't requested so hit CTRL-C to stop said MV. Upon examination of my command, I saw I made a stupid type-o.

Code:
mv -i Doctor/ /*  DoctorWho/


Strictly carelessness on my part. Of course, I was trying to put the wildcard at the end of the "Doctor" files. LOL

So part of my root was moved into a directory it shouldn't be in.

Code:
/home/tlee/Dropbox/iPhoneRingtones/DoctorWho $ ls
'All the Strange, Strange Creatures.m4r'  'Doctor Who Intro 2008 Series 4.m4r'
 bin                                      'Doctor Who Tardis.m4r'
 boot                                      DOCTOR-WHO-Tardis.m4r
'Cloister Bell Tardis Alarm.m4r'          'Doctor Who Theme.m4r'
 dev                                      'Dr Who Opening Season 3.m4r'
'Doctor Who Cybermen 1.mp3'                etc
'Doctor Who Cybermen 2.m4r'               'I Am The Doctor.m4r'
'Doctor Who Dalek 1.m4r'                   The-New-Doctor.m4r
'Doctor Who Dalek 2.m4r'


Since I canceled the execution does mv not 'remove' the files from the original location? Or have the directories partially been moved? Particularly...bin boot dev etc

It doesn't seem as simple as mv'ing back to original location because it is prompting me to overwrite. Won't be shutting down my machine until I know how to fix this.

Thanks...and yes I am a Doctor Who fan...

...and yes...please feel to flame me for my stupidity but preferably after offering a solution. LOL
Back to top
View user's profile Send private message
eccerr0r
Watchman
Watchman


Joined: 01 Jul 2004
Posts: 7134
Location: almost Mile High in the USA

PostPosted: Sun May 27, 2018 4:13 am    Post subject: Reply with quote

If it's on the same filesystem you're probably fine just moving them back.

If they're on different filesystems which appears to be the case, sorry, yeah there's a distinct possibility that there is a partial move. You'll need to go re-merge them back together; I believe most of the time it will copy before deleting by directory. Finding that one directory that got partially handled is the key.

You'll probably need to carefully check how much got copied but not get deleted and move everything else back. Can't really give some good suggestions other than possibly rsyncing or recursive copying everything back without overwriting -- probably OK but may have some files corrupted if you have files open for write...

(sometimes just letting it finish is easier to recover from? eh? ahh...dunno...)
_________________
Intel Core i7 2700K@ 4.1GHz/HD3000 graphics/8GB DDR3/180GB SSD
What am I supposed watching?
Back to top
View user's profile Send private message
Hu
Moderator
Moderator


Joined: 06 Mar 2007
Posts: 13865

PostPosted: Sun May 27, 2018 4:20 am    Post subject: Reply with quote

Did you run this command as your user or as root? If not root, and assuming standard filesystem permissions, then that second glob would have done no harm because your user cannot unlink the system files and directories that /* named.
Back to top
View user's profile Send private message
eccerr0r
Watchman
Watchman


Joined: 01 Jul 2004
Posts: 7134
Location: almost Mile High in the USA

PostPosted: Sun May 27, 2018 6:31 am    Post subject: Reply with quote

Ah yes, another good reason to use root only when necessary... averts many system downing disasters!
_________________
Intel Core i7 2700K@ 4.1GHz/HD3000 graphics/8GB DDR3/180GB SSD
What am I supposed watching?
Back to top
View user's profile Send private message
NeddySeagoon
Administrator
Administrator


Joined: 05 Jul 2003
Posts: 43213
Location: 56N 3W

PostPosted: Sun May 27, 2018 8:20 am    Post subject: Reply with quote

Budoka,

There is no need to flame you. Its a Gentoo learning experience.
Just don't do it again :)

Moving things around on the same filesystem is fast, as no data is copied.
mv just rearranges directory entries.

mv'ing files across filesystems is a copy and delete.
mv'ing directories across filesystems is harder. Its a recursive copy and delete.

Exactly what happens is an implementation detail. If the mv filled up the output filesystem, it might be a mess, just like you have now.
I'm not sure if recursive mv across filesystems does file by file copy and delete or directory by directory copy and delete or ever copies fh. whole thing before it does any deleting.

info '(coreutils) mv invocation'
Code:
   ‘mv’ can move any type of file from one file system to another.
Prior to version ‘4.0’ of the fileutils, ‘mv’ could move only regular
files between file systems.  For example, now ‘mv’ can move an entire
directory hierarchy including special device files from one partition to
another.  It first uses some of the same code that’s used by ‘cp -a’ to
copy the requested directories and files, then (assuming the copy
succeeded) it removes the originals.  If the copy fails, then the part
that was copied to the destination partition is removed.  If you were to
copy three directories from one partition to another and the copy of the
first directory succeeded, but the second didn’t, the first would be
left on the destination partition and the second and third would be left
on the original partition.
So that's what's happened.
_________________
Regards,

NeddySeagoon

Computer users fall into two groups:-
those that do backups
those that have never had a hard drive fail.
Back to top
View user's profile Send private message
Budoka
l33t
l33t


Joined: 03 Jun 2012
Posts: 687
Location: Tokyo, Japan

PostPosted: Mon May 28, 2018 5:29 am    Post subject: Reply with quote

Hu wrote:
Did you run this command as your user or as root? If not root, and assuming standard filesystem permissions, then that second glob would have done no harm because your user cannot unlink the system files and directories that /* named.

I ran it as user. But I must confess I am not familiar with globs so will do some homework.
Back to top
View user's profile Send private message
Budoka
l33t
l33t


Joined: 03 Jun 2012
Posts: 687
Location: Tokyo, Japan

PostPosted: Mon May 28, 2018 5:34 am    Post subject: Reply with quote

NeddySeagoon wrote:
Budoka,

There is no need to flame you. Its a Gentoo learning experience.
Just don't do it again :)

Moving things around on the same filesystem is fast, as no data is copied.
mv just rearranges directory entries.

mv'ing files across filesystems is a copy and delete.
mv'ing directories across filesystems is harder. Its a recursive copy and delete.

Exactly what happens is an implementation detail. If the mv filled up the output filesystem, it might be a mess, just like you have now.
I'm not sure if recursive mv across filesystems does file by file copy and delete or directory by directory copy and delete or ever copies fh. whole thing before it does any deleting.

info '(coreutils) mv invocation'
Code:
   ‘mv’ can move any type of file from one file system to another.
Prior to version ‘4.0’ of the fileutils, ‘mv’ could move only regular
files between file systems.  For example, now ‘mv’ can move an entire
directory hierarchy including special device files from one partition to
another.  It first uses some of the same code that’s used by ‘cp -a’ to
copy the requested directories and files, then (assuming the copy
succeeded) it removes the originals.  If the copy fails, then the part
that was copied to the destination partition is removed.  If you were to
copy three directories from one partition to another and the copy of the
first directory succeeded, but the second didn’t, the first would be
left on the destination partition and the second and third would be left
on the original partition.
So that's what's happened.


Thanks for the detailed explanation. It cleared up some stuff that I was fuzzy on already.

I am going to try to diff the folders and then do a rsync back the other way. Hopefully, that will get the job done. Will report back in later.

Thanks for the words of encouragement. I am glad I was monitoring the output. In the future, I will use extra caution and check my commands before hitting the Enter key. LOL
Back to top
View user's profile Send private message
NeddySeagoon
Administrator
Administrator


Joined: 05 Jul 2003
Posts: 43213
Location: 56N 3W

PostPosted: Mon May 28, 2018 9:47 am    Post subject: Reply with quote

Budoka,

Code:
mv -i Doctor/ /*  DoctorWho/

As a user, the system will try to copy the entire filesystem tree into DoctorWho/

Eventually, that will fail and the filesystem will become full.
The good news in that the user doing the mv is not permitted to delete things that they don't own, so your install is safe.
Damage will be limited to /home/<user_name> and anything the user owned in /tmp and /run

You may find that DoctorWho/ contains copies of the top level system dirs, which you can safely delete.
Had you done this as root ...

The DoctorWho/home/<username>/ dir, if it exists, will need special care.
_________________
Regards,

NeddySeagoon

Computer users fall into two groups:-
those that do backups
those that have never had a hard drive fail.
Back to top
View user's profile Send private message
steveL
Watchman
Watchman


Joined: 13 Sep 2006
Posts: 5153
Location: The Peanut Gallery

PostPosted: Mon May 28, 2018 5:25 pm    Post subject: Re: What happens if mv is stopped mid execution?... Reply with quote

Budoka wrote:
Code:
mv -i Doctor/ /*  DoctorWho/


Strictly carelessness on my part. Of course, I was trying to put the wildcard at the end of the "Doctor" files.
I imagine you were puzzling it at the time, and were not too confident it was correct when you entered it. A very useful tip I got from greycat in ##bash years ago:

Always stick an echo in front of any command you're not sure about; especially if it involves globs (aka "wildcard matches".)

mv was the context back then, and it's still the one I always tend to echo, whenever it's not simply a file in the local directory I've just been editing.

You can't echo a loop, but you can easily echo the command inside it that does something (like alter the fs store); again, very useful to check what you're about to do, before you hose important data.

A quick up-arrow once the output is correct, ctrl-left to beginning of line, zap the echo with del, and enter; takes much longer to describe, than to do.

Another very useful one is to use set -C in your .profile (.bash_profile / .bashrc), or /etc/profile | /etc/bash/bashrc.d/ to set a machine-default. To see what I mean, try this in a terminal:
Code:
set -C
touch unknown
echo > unknown
It has been specified for POSIX sh since the beginning, iirc, so it's not specific to any shell.
Makes hardlinks much more useful than otherwise, since you cannot inadvertently clobber the single data copy (you have to use >| which you are definitely aware of, if you use shell for more than a few minutes per week); only overwrite it with a command.
mv in particular no longer removes the last link, and given set -C, you always have the data (barring glob mishaps..;)

Personally, I think it should be activated by default, since it makes sh a cleaner, more robust language.

HTH.
Back to top
View user's profile Send private message
khayyam
Watchman
Watchman


Joined: 07 Jun 2012
Posts: 6228
Location: Room 101

PostPosted: Tue May 29, 2018 3:31 pm    Post subject: Reply with quote

Budoka, et al ... another situation in which zsh does the right thing:

Code:
% cd $(mktemp -d)
% touch {a-e}.txt
% zmv -nv *.txt /tmp
mv -- a.txt /tmp
mv -- b.txt /tmp
mv -- c.txt /tmp
mv -- d.txt /tmp
mv -- e.txt /tmp
% ls *.txt
a.txt  b.txt  c.txt  d.txt  e.txt
% zmv *.txt /tmp
% ls /tmp/*.txt
/tmp/a.txt  /tmp/b.txt  /tmp/c.txt  /tmp/d.txt  /tmp/e.txt

You can also use/test globs in a variety of ways ...

Code:
% zmv -nv '/tmp/(*).txt' '$1.sh'
mv -- /tmp/a.txt a.sh
mv -- /tmp/b.txt b.sh
mv -- /tmp/c.txt c.sh
mv -- /tmp/d.txt d.sh
mv -- /tmp/e.txt e.sh
% zmv '/tmp/(*).txt' '$1.sh'
% ls
a.sh  b.sh  c.sh  d.sh  e.sh
% i=0; for f (*.sh) zmv $f '${(l:3::0:)$((++i))}'$f
% ls
001a.sh  002b.sh  003c.sh  004d.sh  005e.sh

best ... khay
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Installing Gentoo All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum