4

Currently, i am trying to copy a directory with files that contain my works website from a Gentoo server to a USB drive. Ive combed through many pages of you youtube and google and cannot seem to get it to copy. Im sure there is something im dong wrong here, anyone have any ideas?

cp -r /opt/biweb/app/ /data/dev/sdb1/


Edit: mount points

df-h
Filesystem Size Used Avail Use% Mounted on
/dev/sda3  31G  31G  0     100% /
/dev/sda1  84m  9.5m 70m   12%  /boot

/dev/sdb1  68g 42g   23g   66%  /data
1
  • What happens when you run cp -r /opt/biweb/app/ /data/dev/sdb1/ and what exactly do you want to happen? Did you encounter any warning or error messages? Please reproduce them in their entirety in your question. You can select, copy and paste terminal content and most dialogue messages in Ubuntu. (see How do I ask a good question?) Mar 25, 2017 at 10:44

2 Answers 2

5

The command you want is:

cp -r /opt/biweb/app/* /dev/sdb1/

Don't forget the asterix (*)! The above command will copy everything in the /app folder into the /sdb1 folder.

If you want to copy the app folder itself into the destination, then do:

cp -r /opt/biweb/app /dev/sdb1/

The above has no trailing slash after "app". This will copy the app folder as well as its contents.

10
  • I've updated the answer. You just remove the trailing slash and asterix from the source path.
    – Delorean
    Mar 22, 2017 at 16:53
  • Thanks for the help, but unfortunately neither option worked. I first got "specified destination directory does not exist". Second i got, "no such file or directory." Mar 22, 2017 at 19:07
  • Oh and it is mounted, its mounted on /data/. I must have something wrong along the way. Mar 22, 2017 at 19:10
  • Correct, it's likely not /data/dev/sdb1/ but instead /dev/sdb1/. I've edited my answer to reflect that.
    – Delorean
    Mar 22, 2017 at 19:12
  • Apologies, I'm trying to learn this as I go for work. That didnt work either. Mar 22, 2017 at 19:20
5

The device description for the partition on the USB drive is

/dev/sdxn

where x is the drive letter and n is the partition number, In your case it seems to be /dev/sdb1. But you should not write directly to the device. Instead you should mount it and write to the file system at the mountpoint. First you should create a mountpoint, or use one that already exists. Text after # is a comment (not used as a command).

sudo mkdir /mnt/sdn            # only the first time
sudo mount /dev/sdxn /mnt/sdn

or in your case

sudo mkdir /mnt/sd1
sudo mount /dev/sdb1 /mnt/sd1

You may want to make sure that you are allowed to write to the USB pendrive from a regular user by the following method,

sudo mkdir -p /mnt/sd1  # only if you want a new mountpoint
sudo umount /dev/sdxn   # general: only if already mounted (with bad permissions).
sudo umount /dev/sdb1   # example

sudo mount -o rw,users,umask=000 /dev/sdxn /mnt/sd1  # general: mount
sudo mount -o rw,users,umask=000 /dev/sdb1 /mnt/sd1  # example

ls -ld /mnt/sd1                          # check permissions

sudo bash -c "echo 'Hello World' > /mnt/sd1/hello.txt"  # test writing with sudo
cat /mnt/sd1/hello.txt                   # test reading (as user)
ls -l /mnt/sd1                           # check permissions of the content
rm /mnt/sd1/hello.txt                    # test removing (as user)
echo 'I am a user' > /mnt/sd1/user.txt   # test writing (as user)

Edit 1: Sometimes (I would even say often) the partition on the USB drive will be mounted automatically. You will find it with the following commands,

df -h
sudo lsblk -f
sudo lsblk -m

The automatic mounting may or may not make it read-write for the regular user, but it will usually be possible to write with superuser privileges, with sudo.

You can inspect how it is mounted with the command

mount

but it will display a lot of information (about everything that is mounted).

Edit 2: copying command

After finding out that the pendrive is automatically mounted on /data, the following command line should work, if [the partition in] the USB drive is mounted read/write and with permissions for your regular user ID.

cp -r /opt/biweb/app /data

It should create a directory /data/app on the USB drive with the content (the directory tree and the files). If it does not work, you can try the special mounting method, that I showed above, but modified for the current mountpoint,

sudo umount /data                                 # unmount
sudo mount -o rw,users,umask=000 /dev/sdb1 /data  # mount with 'full' permissions

Edit 3: Please edit your original question, where you can use formatting tools.

enter image description here

1
  • Comments are not for extended discussion; this conversation has been moved to chat.
    – terdon
    Mar 23, 2017 at 16:35

Not the answer you're looking for? Browse other questions tagged .