LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   copying Dir to a usb thumb drive (https://www.linuxquestions.org/questions/linux-general-1/copying-dir-to-a-usb-thumb-drive-879718/)

drmjh 05-09-2011 04:25 PM

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

TobiSGD 05-09-2011 04:59 PM

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.

SaintDanBert 05-09-2011 07:58 PM

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

drmjh 05-10-2011 07:43 AM

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#


TobiSGD 05-10-2011 08:23 AM

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

SaintDanBert 05-10-2011 09:05 AM

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

peter1234 05-10-2011 11:28 AM

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.

drmjh 05-10-2011 01:30 PM

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


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