LinuxQuestions.org
Visit Jeremy's Blog.
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 12-27-2005, 04:52 PM   #1
BillyGalbreath
Member
 
Registered: Nov 2005
Location: Houston Texas
Distribution: Debian Sid
Posts: 379

Rep: Reputation: 31
Copying files as root without changing permissions


About a week ago I transfered all files from one hard drive to the other to move my distro to a newer hard drive. I booted my computer up with a live cd and entered the shell as root. I mounted my new hard drive as /mnt/new and mounted my old hard drive as /mnt/old. I then proceeded to copy the files the only way I knew how.

# cp -Rv /mnt/old /mnt/new

I did it verbosely so I could see when it was done from across the room as I watched television.

Anyways. The copy was successful. Every file was copied to the new drive. So I shut down the pc, took out the old hard drive and set the new one as the main. I then proceeded to boot up.

First problem... no grub. So I used a floppy to install grub to the MBR. No problem.

I continued on a booted up my debian. I got all the way to the KDM login screen. I tried to login but the screen flickered and then went back to the KDM screen to login again. I swear I must have logged in 20 times before i stopped...

I then went to command line and i was able to login as user and root... Hmm... so I viewed my hard drive to make sure all the files were there:

# ls -al /

This is when I noticed... Every folder and every file is now owned by user root and group root. I supposed this was the problem and i decided i didnt want to fool with it again, so I just did a clean installation from scratch.


Now I am at a point again where I need to copy over more files from one hard drive to another (different machine). How can I copy all the files over to a new hard drive yet leave the permissions untouched?
 
Old 12-27-2005, 05:25 PM   #2
GrueMaster
Member
 
Registered: Aug 2005
Location: Oregon
Distribution: Kubuntu.
Posts: 848

Rep: Reputation: 30
cd <source> ; tar -cf - . | (cd <dest> ; tar -xvf -)

Where <source> and <dest> are the source and destination directory locations. Example:

cd /mnt/hda1 ; tar -cf - . | (cd /mnt/hdb1 ; tar -xvf -)

This is faster, because one thread is reading from the source, and another is writting to the destination. Simple but effective example of multithreading. Speed is ~1.8x as fast as regular copying, and even faster when the source & destination are on separate devices & controllers.
 
Old 12-28-2005, 08:18 AM   #3
BillyGalbreath
Member
 
Registered: Nov 2005
Location: Houston Texas
Distribution: Debian Sid
Posts: 379

Original Poster
Rep: Reputation: 31
And this will leave all file and directory permissions unchanged?
 
Old 12-28-2005, 08:39 AM   #4
Guttorm
Senior Member
 
Registered: Dec 2003
Location: Trondheim, Norway
Distribution: Debian and Ubuntu
Posts: 1,453

Rep: Reputation: 447Reputation: 447Reputation: 447Reputation: 447Reputation: 447
cp also has an option -p to preserve permissions

# cp -Rpv /mnt/old /mnt/new
 
  


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
changing permissions of document root and cgi-bin abtimoteo Ubuntu 2 08-13-2005 09:36 AM
changing permissions and ownership on many files and folders Cinematography Linux - General 4 08-01-2005 03:20 AM
Changing Permissions in Root tgreiner Linux - Newbie 3 02-04-2005 09:58 AM
Changing permissions on VFAT files bluesailor Linux - Software 7 10-08-2003 06:57 PM
Copying files to desktop w/out being root Lon3wolf Linux - Newbie 8 07-10-2003 12:00 PM

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

All times are GMT -5. The time now is 10:58 AM.

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