0

I am looking to copy a file from a sub-directory on my Ubuntu 16.04 system to an external USB drive (this one) using the CLI. The drive has the following file and folder structure:

/Backup
/Backup/Jan_02_2016
/Backup/Jun_02_2016
robert_11042016.pdf
pre_install_15102014.pdf
Magazine_2012.pdf

I need to create a new sub-directory named /Backup/Dec_02_2016. Then I need to copy /home/User_F_Readout/Downloads/Temp_Report_56_09242016.txt to a new sub-directory /Backup/Dec_02_2016 on the usb drive.

Previously, I have only copied files to the main directory of the external drive, so I did not need to create sub-directories - I would just mount the drive with

mount /dev/sdb1 /mnt/usb

and then just copy the file to /mnt/usb. This would place the file in the main directory of the external USB drive and then I could unmount.

Problem:

Here, the problem I am facing is that I now need to place the file in the subdirectory /Backup/Dec_02_2016 and not in the main directory of the drive. I had a look here but it does not indicate how to mount the drive to a mount point with the proper sub-directory structure.

Question:

Is there a way to place this file directly in the sub-directory? Or do I need to place it in the main directory and then move it?

Pang
  • 371
  • 1
  • 5
  • 12
edesz
  • 763
  • 3
  • 11
  • 19

2 Answers2

2
  1. Mount the device as /mnt/usb

  2. Create a folder

    mkdir -p  /mnt/usb/Backup/Dec_02_2016
  3. Copy to the recently mounted device

    cp -p /home/User_F_Readout/Downloads/Temp_Report_56_09242016.txt /mnt/usb/Backup/Dec_02_2016
Larry R. Irwin
  • 377
  • 3
  • 7
1

You can simply use move command and set path of hard disk.

sudo mv fromPath/ /media/username/harddisk name/

Thanks.

Sohel Khan
  • 111
  • 1