I have a group of folders (L1N-L5N), in which I want to copy from my /home/michael/documents/XXX to my Dropbox folder. At present, I have used the following script:

cp -ra /home/michael/Documents/GeneralNetwork /GNI /home/michael/Dropbox/NetworkData
cp -ra /home/michael/Documents/GeneralNetwork /L1N /home/michael/Dropbox/NetworkData
cp -ra /home/michael/Documents/GeneralNetwork /L2N /home/michael/Dropbox/NetworkData
cp -ra /home/michael/Documents/GeneralNetwork /L3N /home/michael/Dropbox/NetworkData
cp -ra /home/michael/Documents/GeneralNetwork /L4N /home/michael/Dropbox/NetworkData
cp -ra /home/michael/Documents/GeneralNetwork /L5N /home/michael/Dropbox/NetworkData

This works, but poorly.

I am also unsure of the reasoning as to why it returns this:

cp: cannot stat ‘/GNI’: No such file or directory
cp: cannot stat ‘/L1N’: No such file or directory
cp: cannot stat ‘/L2N’: No such file or directory
cp: cannot stat ‘/L3N’: No such file or directory
cp: cannot stat ‘/L4N’: No such file or directory
cp: cannot stat ‘/L5N’: No such file or directory

I have thought of shortening it down:

cp -ra /home/michael/Documents/GeneralNetwork/L*

Or some other wildcard to pickup all folders containing "L". What I want is to copy the files (and overwrite) to the folder in this directory, however I cannot be certain they will fall under the above Folder Name Scheme.

What is the best way to create a .sh file to copy everythig from .../GeneralNetwork/* without copying hidden files etc? I have done the ../GeneralNetwork/. and it included boot, bin, sys etc.

  • If there is a space between files, put it between quotes: "/home/michael/Documents/GeneralNetwork /GNI" – blade19899 Oct 6 '14 at 8:27
  • 1
    You really have a directory called "GeneralNetwork " with a space at the end? Why? Your problem with copying boot etc is probably that space; is that a typo? --- anyway, consider using tools like Unison for this kind of job --- see for example askubuntu.com/a/522423/16395 – Rmano Oct 6 '14 at 8:37
  • Rmano, sorry that was not a typo- I did not even note it, as I was editing it from LeafPad..which was a stupid mistake. This issue has been corrected. Thank you. – DankyNanky Oct 6 '14 at 9:04

cp: cannot stat ‘/GNI’: No such file or directory

That's because of the whitespace:

cp reads it like this:

cp -ra /home/michael/Documents/GeneralNetwork /GNI

That the folder: /home/michael/Documents/GeneralNetwork needs to be copied to /GNI. But there is no folder in /GNI, therefore the error.

If there is a whitespace between files, put it between quotes:

"/home/michael/Documents/GeneralNetwork /GNI"

cp is seeing:


Withing quotes, it will read beyond the whitespace:

cp -ra "/home/michael/Documents/GeneralNetwork /GNI" /home/michael/Dropbox/NetworkData

Per user request:

If i understand you correctly, you want to copy /home/michael/Documents/GeneralNetwork

and everything in it. Yes that is possible, like so:

cp -ra "/home/michael/Documents/GeneralNetwork /*.*" /home/michael/Dropbox/NetworkData
  • Thank you, that would make logical sense. I ammend the script and test. On another note however, is there an ability to make a wildcard so my "script" just copies the folder? I mean, ideally I'd like to just copy /home/michael/Documents/GeneralNetwork and ignore all system files. – DankyNanky Oct 6 '14 at 8:48
  • @MichaelNancarrow, i updated my answer. Due note, the code is at the top of my head. Am on a Windows machine right now, and have no ability to test it on a Linux system. – blade19899 Oct 6 '14 at 8:53
  • @MichaelNancarrow, also note, if this answered your question, it is generally preferred, that one accept it as 'accepted answer' (checkbox below the up and down arrow). – blade19899 Oct 6 '14 at 8:55
  • 1
    Blade, using . is not a valid commend, is it? – DankyNanky Oct 6 '14 at 9:05
  • 1
    @MichaelNancarrow, Using a dot can be used as a valid command, see: source or dot operator Man Page | Bash | SS64.com. eg ./script.sh. – blade19899 Oct 6 '14 at 9:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.