LinuxQuestions.org
Visit the LQ Articles and Editorials section
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 05-09-2011, 04:25 PM   #1
drmjh
Member
 
Registered: Mar 2005
Location: North Carolina, USA
Distribution: Ubuntu 12.04LTS
Posts: 258

Rep: Reputation: 31
copying Dir to a usb thumb drive


I want to copy my /home to a USB thumb drive recursively.
I've wrestled with this for a few hours now and continue to spin my wheels.

The device is listed in my Disk Utility as /dev/sdc.
However a little further down it is listed as /dev/sdc1 ?
Anyway, I relabeled the volume as usb stick and formatted it to Ext4. I mounted it at /media/usb stick

Do I have to enter this drive into the fstab? If so, how? what do I write?

Using the command : cp -R (what follows... I want to copy /home recursively to the usb thumb drive.)
Your help is appreciated.

Matthew
 
Old 05-09-2011, 04:59 PM   #2
TobiSGD
Moderator
 
Registered: Dec 2009
Location: Hanover, Germany
Distribution: Gentoo
Posts: 15,424
Blog Entries: 2

Rep: Reputation: 3996Reputation: 3996Reputation: 3996Reputation: 3996Reputation: 3996Reputation: 3996Reputation: 3996Reputation: 3996Reputation: 3996Reputation: 3996Reputation: 3996
Some hints:
- /dev/sdc is the actual device, while /dev/sdc1 is the partition on it. Keep in mind that you have to mount the partition, not the device

- using file-names that contain spaces is not a good idea on Linux, because you will have to escape the space every time you type it. That means you have to write the name of the directory like this usb\ stick.

So to copy your home directory you have to write
Code:
cp -R /home /media/usb\ stick
- You don't have to make an entry for that drive in /etc/fstab.
 
2 members found this post helpful.
Old 05-09-2011, 07:58 PM   #3
SaintDanBert
Senior Member
 
Registered: Jan 2009
Location: Austin, TX
Distribution: Mint-15 with Cinnamon & KDE
Posts: 1,324
Blog Entries: 3

Rep: Reputation: 86
Using the copy command "cp" the option -R simply asks for a recursive copy of folder and sub-folders.

Consider using the --archive or -a option. According to my man page, --archive
results in:
Code:
--no-dereference ..... never follow symbolic links in the SOURCE path
--preserve=all ....... attributes might be: mode,ownership,timestamps,context,links,xattr,
all
If you follow a sym-link, the files or folders being pointed at get copied. Otherwise, the sym-link itself gets copied as a lone file.

Another way to do this involves using tar into a pipe instead of a file.
The pipe then uses tar again to read the pipe. tar is somewhat smarter than
cp when it comes to duplicating complex trees of files and folders.

~~~ 0;-Dan
 
1 members found this post helpful.
Old 05-10-2011, 07:43 AM   #4
drmjh
Member
 
Registered: Mar 2005
Location: North Carolina, USA
Distribution: Ubuntu 12.04LTS
Posts: 258

Original Poster
Rep: Reputation: 31
Many thanks, TobisGD and SaintDanBert.
I've had some success. I changed the volume name to get rid of the SPACE.
I was able to create a dir on the USB /bkhome. But I'm mussing something and keep getting Err. Msg.s.

Code:
root@mjh-desktop:~# cp -R  /home/media/usbstick/
cp: missing destination file operand after `/home/media/usbstick/'
Try `cp --help' for more information.
root@mjh-desktop:~# cp -R  /home  bkhome/media/usbstick
cp: cannot create directory `bkhome/media/usbstick': No such file or directory
root@mjh-desktop:~# cp -R  /home  bkhome/media/usbstick
cp: cannot create directory `bkhome/media/usbstick': No such file or directory
root@mjh-desktop:~# cd /media/usbstick
root@mjh-desktop:/media/usbstick# mkdir bkhome
root@mjh-desktop:/media/usbstick# ls
bkhome  lost+found
root@mjh-desktop:/media/usbstick# cp -R  /home  bkhome/media/usbstick
cp: cannot create directory `bkhome/media/usbstick': No such file or directory
root@mjh-desktop:/media/usbstick#
 
Old 05-10-2011, 08:23 AM   #5
TobiSGD
Moderator
 
Registered: Dec 2009
Location: Hanover, Germany
Distribution: Gentoo
Posts: 15,424
Blog Entries: 2

Rep: Reputation: 3996Reputation: 3996Reputation: 3996Reputation: 3996Reputation: 3996Reputation: 3996Reputation: 3996Reputation: 3996Reputation: 3996Reputation: 3996Reputation: 3996
You don't specify the right path. You have created the directory bkhome on your stick, which is mounted on /media/usbstick. So the correct path is /media/usbstick/bkhome. Also consider the -a option recommended by SaintDanBert.

So your correct command should be:
Code:
cp -aR /home /media/usbstick/bkhome
 
1 members found this post helpful.
Old 05-10-2011, 09:05 AM   #6
SaintDanBert
Senior Member
 
Registered: Jan 2009
Location: Austin, TX
Distribution: Mint-15 with Cinnamon & KDE
Posts: 1,324
Blog Entries: 3

Rep: Reputation: 86
The --archive(-a) option includes --recursive(-R).

Also, one reason to pipe tar to tar involves the issues of target folders.
tar seems to deal with folder creation with fewer troubles while cp wants the targets to exist in some cases.

~~~ 0;-Dan
 
1 members found this post helpful.
Old 05-10-2011, 11:28 AM   #7
peter1234
Member
 
Registered: Apr 2009
Posts: 42

Rep: Reputation: 2
Hi drmjh

This is not what you asked for..... but I think you should know this.
Putting a journaling FS on a pendrive seems bad,
because FS will use a part of the pendrive for journaling (many read/write cycles on the journaling block),
flash memory cells will "die" faster this way.
 
1 members found this post helpful.
Old 05-10-2011, 01:30 PM   #8
drmjh
Member
 
Registered: Mar 2005
Location: North Carolina, USA
Distribution: Ubuntu 12.04LTS
Posts: 258

Original Poster
Rep: Reputation: 31
TobisSGD, vielen Dank!

SaintDanBert, many thanks, I will make notes on this now for future reference.

Peter1234, I didn't know that and will keep it in mind.

Basically, I just wanted a quick place to keep my data while I updated the OS. My next task is to set up Unison, synchronize my laptop and desktop and store a copy on the Ubuntu cloud.

Matthew
 
  


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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Using a usb thumb drive or flash drive as a swap partition. stevenjoseph Linux - Hardware 8 01-16-2012 12:09 PM
Only root can automount CD drive and USB thumb drive km4hr Red Hat 3 03-25-2009 12:30 PM
USB Thumb Drive as Home Dir blueAlien Slackware 5 05-30-2007 01:43 PM
USB drive using different partitions (usb key thumb drive) Arodef Linux - Hardware 0 08-04-2004 06:36 PM
USB thumb drive works great, but I still can't get my USB mouse to work. blk96gt Slackware 8 06-22-2004 01:52 AM


All times are GMT -5. The time now is 04:19 AM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration