LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 05-17-2010, 11:14 AM   #1
dopraaditya
LQ Newbie
 
Registered: May 2010
Posts: 2

Rep: Reputation: 0
accidently moved files in "/" to a folder


Hi everybody ,

Did a basic mistake . Dnt know how to recover .

In root user i gave a command

mv / /home/username/

except the home directory all the other folders that is /sbin /lib /opt
etc was moved to /home/username.Now i am unable to execute any command.

I also tried to set the PATH and LD_LIBRARY_PATH to the newly copied localtion but none of the command works. Since "mv" command also not working i am unable to change the location. Pls let me know if somebody has a solution for this.
 
Old 05-17-2010, 11:36 AM   #2
alli_yas
Member
 
Registered: Apr 2010
Location: Johannesburg
Distribution: Fedora 14, RHEL 5.5, CentOS 5.5, Ubuntu 10.04
Posts: 559

Rep: Reputation: 92
Hi,

Two things:

1. What distro & version are you using? If Fedora/RHEL/CentOS, you can boot into rescue mode and move stuff back.

2. I think your issue pretty much shows why you should avoid logging in as root directly - always try to make use of sudo.

Cheers,
Yas
 
Old 05-17-2010, 11:50 AM   #3
repo
LQ 5k Club
 
Registered: May 2001
Location: Belgium
Distribution: Arch
Posts: 8,527

Rep: Reputation: 898Reputation: 898Reputation: 898Reputation: 898Reputation: 898Reputation: 898Reputation: 898
Quote:
2. I think your issue pretty much shows why you should avoid logging in as root directly - always try to make use of sudo.
Quote:
sudo mv / /home/username/
will give the same result.
You can try to give the whole path to the mv command

Last edited by repo; 05-17-2010 at 11:56 AM.
 
Old 05-17-2010, 11:58 AM   #4
jiml8
Senior Member
 
Registered: Sep 2003
Posts: 3,171

Rep: Reputation: 115Reputation: 115
Refer to the commands you need by the full path name. Thus instead of mv, use /home/username/bin/mv

So, for instance, to move /home/username/usr back to /usr, use
Code:
/home/username/bin/mv /home/username/usr /usr
and that should put it back for you.

PS: I've done things like that too. Once managed to move all of /usr/bin into /usr/local/bin. I recovered by cd'ing into a backup directory, then deleting /usr/bin and /usr/local/bin, and copying everything back into them out of the backup.
 
Old 05-17-2010, 12:02 PM   #5
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,576
Blog Entries: 31

Rep: Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195
Did you export PATH and LD_LIBRARY_PATH?
 
Old 05-17-2010, 12:39 PM   #6
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Arch/XFCE
Posts: 17,802

Rep: Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738
I say don't mess with PATH---as already stated, just give the full pathname for the commands you need to run.

You could also boot up from a Linux Live-CD, and sort things out from there.
 
Old 05-18-2010, 03:35 AM   #7
alli_yas
Member
 
Registered: Apr 2010
Location: Johannesburg
Distribution: Fedora 14, RHEL 5.5, CentOS 5.5, Ubuntu 10.04
Posts: 559

Rep: Reputation: 92
Quote:

Quote:
sudo mv / /home/username/

will give the same result.
You can try to give the whole path to the mv command
Agreed

The point I'm trying to make is that when logged in as root its easy to make such a mistake - vs sudo where you are forced to enter your password and thus this reminds you that you're running a priveleged (and potentially dangerous) command.

Not saying this will stop beginner's from making mistakes - but just another way you can protect against doing stuff that will destroy a system
 
Old 05-18-2010, 08:11 AM   #8
Valery Reznic
ELF Statifier author
 
Registered: Oct 2007
Posts: 675

Rep: Reputation: 136Reputation: 136
You have to use following command to rescue your /lib and /bin:
Code:
/home/username/lib/ld-linux.so.2 --library-path /home/username/lib /home/username/bin/mv /home/username/lib /home/username/bin /
After that you can use any programs in /bin as usual and restore the rest
 
Old 05-18-2010, 08:55 AM   #9
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,576
Blog Entries: 31

Rep: Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195
Quote:
Originally Posted by Valery Reznic View Post
Code:
/home/username/lib/ld-linux.so.2 --library-path /home/username/lib /home/username/bin/mv /home/username/lib /home/username/bin /
Nice! For those like me who knew nothing about ld-linux.so.2, this page may be helpful.
 
Old 05-18-2010, 09:04 AM   #10
avee137
Member
 
Registered: Apr 2010
Location: bangalore,india
Distribution: ubuntu 9.10,CentOS 5
Posts: 120

Rep: Reputation: 16
boot the system n single user mode and move back the files to their original directory.
use these links for booting in single user mode:
http://www.redhat.com/docs/manuals/l...ng-single.html
http://www.cyberciti.biz/faq/grub-bo...gle-user-mode/

Last edited by avee137; 05-18-2010 at 09:06 AM.
 
Old 05-18-2010, 09:08 AM   #11
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Arch/XFCE
Posts: 17,802

Rep: Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738
avee;

Since the system commands got moved to different directories---thus making PATH invalid---how would booting to single-user mode help?
 
Old 05-18-2010, 09:21 AM   #12
avee137
Member
 
Registered: Apr 2010
Location: bangalore,india
Distribution: ubuntu 9.10,CentOS 5
Posts: 120

Rep: Reputation: 16
Quote:
Originally Posted by pixellany View Post
avee;

Since the system commands got moved to different directories---thus making PATH invalid---how would booting to single-user mode help?

Setting the pathname temporarily to the files current location may do.I am not sure about the solution.I just suggested a trial.
 
Old 05-18-2010, 04:01 PM   #13
Valery Reznic
ELF Statifier author
 
Registered: Oct 2007
Posts: 675

Rep: Reputation: 136Reputation: 136
Quote:
Originally Posted by avee137 View Post
Setting the pathname temporarily to the files current location may do.I am not sure about the solution.I just suggested a trial.
After such damage system will not be able to reboot (if you have a spare one you can try).

Once I have to rescue our web-server using trick with ld-linux (I didn't do 'mv', I was only asked to help)

As long as I know - short me full re-install - solution either ld trick or boot from the live cd.
 
Old 05-19-2010, 01:21 AM   #14
dopraaditya
LQ Newbie
 
Registered: May 2010
Posts: 2

Original Poster
Rep: Reputation: 0
Hi everbody,

I was able to solve the problem using the ld trick. (also learnt abt the dynamic loader module).
Thanks a ton all u guys
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] There is no "menu.lst" in my Ubuntu "/boot/grub/" folder. msbstar Linux - Newbie 18 09-15-2012 02:26 PM
samba - windows files lose "created on" date stamp when moved to samba share on linux jaredk51 Linux - Software 5 02-19-2010 04:13 PM
Comparison to "Program Files" Folder in Linux? Ascendancy5 Linux - Newbie 11 01-15-2009 07:45 AM
C Drive "/dev/hda1" accidently used in dd command at "of=" switch M D Linux - Software 4 04-26-2007 09:56 AM
Moved files => Apache: "You don't have permission to access / on this server." teek Linux - Server 1 12-31-2006 05:03 AM


All times are GMT -5. The time now is 02:34 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration