Copying from mount share drive to local folder through script

25,321

Solution 1

No your commands should look like following

  rm -rfv /home/user/Documents/Exercise/*

because folder Exercise can have subdirectories

and in case of a samba share first you have to mount it locally

i.e.

mount -t smbfs smb://"server/arc/Exercise Files/Word/" /mnt 

and then do

 cp /mnt /home/user/Documents/Exercise/

Solution 2

You have to use the "minus r" flag or -r

rm -r

and

cp -r

This will copy or delete recursively into folders or files within files.

Share:
25,321

Related videos on Youtube

Mitchell
Author by

Mitchell

Updated on September 18, 2022

Comments

  • Mitchell
    Mitchell over 1 year

    This is my first time trying to work with Linux Scripts so this may be something obvious.

    Here is what I am trying to do:

    1. Remove all contents from local folder - rm /home/user/Documents/Exercise/
    2. Copy files from a shared windows network drive - cp smb://server/arc/Exercise%20Files/Word/

    So from my understanding my command should look like this

      rm /home/user/Documents/Exercise/
      cp smb://server/arc/Exercise%20Files/Word/ /home/user/Documents/Exercise/
    

    But anytime I try and run either of the above commands I get the following error:

      "rm: cannot remove `/home/user/Documents/Exercise/': Is a directory"
      "cp: cannot stat `smb://server/arc/Exercise%20Files/Word/': No such file or directory"
    

    What am I doing wrong?

    Kind Regards,

    M

    EDIT:

    I now have the rm function working yet am still troubled by the cp function. To ensure it is not an issue with the spaces in the folder names I have renamed the folders on the share so it now reads: //server/Arc/ExerciseFiles/*

    I have mounted the folder so I (assume) no longer need the smb://. It currently reads: cp -rfv /home/user/Documents/ExerciseShare/ExerciseFiles/Word/ /home/user/Documents/Exercise/

    M

  • Registered User
    Registered User about 11 years
    if there are blank spaces in your directory names I feel they probably are causing the problem so you can do some thing like quoting the names in double quotes ""
  • Mitchell
    Mitchell about 11 years
    OP updated. rm command resolved thankyou. Still issues with cp.
  • Registered User
    Registered User about 11 years
    sudo apt-get install smbfs This will install the samba filesystem package on your system, simply re-run the mount command when you’ve got this package sirnet.co.uk/archives/114
  • Mitchell
    Mitchell about 11 years
    I think it must have been the %20 in the originals. I restarted the machine and used the exact same command and it worked!
  • Mitchell
    Mitchell about 11 years
    the following command worked - cp -rfv /home/user/Documents/ExerciseShare/ExerciseFiles/Word/ /home/user/Documents/Exercise/ thankyou for all your help!