Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
[SOLVED] files moved
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Other Things Gentoo
View previous topic :: View next topic  
Author Message
Vieri
Guru
Guru


Joined: 18 Dec 2005
Posts: 347

PostPosted: Tue Sep 03, 2013 9:48 am    Post subject: [SOLVED] files moved Reply with quote

Hi,

Just for the kicks of it I tried the following command:

mv ./* *

What should I expect from this?

Not that I was trying to run this but it was a typo and some files moved in a way I don't understand yet.
I had:
./file1
./subdir1
./subdir1/file2

After the command I had:
./subdir1
./subdir1/file1
./subdir1/file2

Why is that?
Does the second * expand to the fisrt dir name?
I wonder what would happen if I had several subdirs and more subdirs within them.

Thanks for shedding some light on this,

Vieri

[EDIT] OK, it seems that with this command all files and folders are moved to the 'last' subdir.
Back to top
View user's profile Send private message
eccerr0r
Advocate
Advocate


Joined: 01 Jul 2004
Posts: 3601
Location: USA

PostPosted: Tue Sep 03, 2013 8:09 pm    Post subject: Reply with quote

This is why sometimes Unix can be confusing.
If you had in your current directory

file1 filedir2(directory) filex1

and you mv ./* *

This, if you have a recent version of coreutils, will fail.

This would expand to mv ./file1 ./filedir2 ./filex1 file1 filedir2 filex1

It will notice that filex1 is not a directory and will complain and not do anything. Since you had a directory as the last element in your example (in * sort order) it will actually do something (as if filex1 was a directory) - it wouldn't move the directory into itself but would move all the files there. If you did this command on an old unix, it will happily clobber everything causing massive data loss.
_________________
Intel Core i7 2700K@ 4.1GHz/HD3000 graphics/8GB DDR3/180GB SSD
What am I supposed to be advocating?
Back to top
View user's profile Send private message
Vieri
Guru
Guru


Joined: 18 Dec 2005
Posts: 347

PostPosted: Wed Sep 04, 2013 10:31 am    Post subject: Reply with quote

Thanks for the explanation.
A colleague has actually run this command from top level root:

/ # mv /* *

and that really screwed things up.
No files or directories were deleted and they seem to all be within the 'last' directory named 'zstore' on this particular system.

Funny thing now is to try to move the directories back to their original places.
The 'mv' command is now in /zstore/bin and trying to run it gives an error (command not found).
I guess it may be because it needs to find some shared libs such as:
librt.so.1, libacl.so.1, libc.so.6
and I'm not sure how to inform it to look into /zstore/lib.. etc (maybe with ldconfig).

'mv' is in bin, not sbin so it isn't statically linked.
I don't know of any binary in sbin that can actually move a directory.
But since ldconfig is in sbin then maybe I can have better luck with that.

Of course, mounting the system with a "live CD" and moving the directories is a simpler approach but this is a production server that we'd like to keep running, at least for now.
Back to top
View user's profile Send private message
eccerr0r
Advocate
Advocate


Joined: 01 Jul 2004
Posts: 3601
Location: USA

PostPosted: Wed Sep 04, 2013 12:00 pm    Post subject: Reply with quote

Yes that would be very painful. Maybe if people are prone to doing that either they shouldn't be root, or you can create a file /zzzzzzzz that coreutils will pick up and barf if you try doing a move to * :)

Tips and tricks:

Gentoo however has a fallback in case you mess up your dynamic libraries: Busybox. In normal installations that you don't get rid of it, Gentoo will build busybox statically in /bin. If you messed up your /lib, breaking all your dynamic binaries, you can use

/bin/busybox mv file2 file1

to move file2 back to file1. Because it's statically linked, it doesn't matter that your linker libraries are broken, so you should be able to use this to repair. Busybox is a "swiss army knife" tool that contains a whole bunch of unix commands - Just like a swiss army knife, it has lots of different functions but not great at any one thing - but will get you out of a jam.
_________________
Intel Core i7 2700K@ 4.1GHz/HD3000 graphics/8GB DDR3/180GB SSD
What am I supposed to be advocating?
Back to top
View user's profile Send private message
Vieri
Guru
Guru


Joined: 18 Dec 2005
Posts: 347

PostPosted: Wed Sep 04, 2013 1:35 pm    Post subject: Reply with quote

Hey, you're a lifesaver. I didn't think of using busybox and it's awesome.
I finally restored all the subdirs and banned the use of mv /* * ;-)
Thanks!
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Other Things 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