Find the answer to your Linux question:
Results 1 to 5 of 5
Hopefully somebody can help me out. I'm having trouble copying files as my source directory has spaces in them. Example: cp -m "//server1/directory 1/filename1" "//server2/directory 2/filename2" using wildcards cp -m ...
  1. #1
    Just Joined!
    Join Date
    Feb 2008
    Posts
    2

    korn shell / filenames and directories with spaces

    Hopefully somebody can help me out. I'm having trouble copying files as my source directory has spaces in them.

    Example:
    cp -m "//server1/directory 1/filename1" "//server2/directory 2/filename2"

    using wildcards
    cp -m "//server1/directory 1/*.filetype" "//server2/directory 2/"

    I get the file not file error. Does anybody have any suggestions? Thanks in advance!

  2. #2
    Linux Newbie
    Join Date
    Jan 2008
    Location
    UK
    Posts
    211
    Use cp with the -r option
    cp -r "folder one/" "folder two/"

  3. #3
    Just Joined!
    Join Date
    Feb 2008
    Posts
    2
    Quote Originally Posted by wowbag1 View Post
    Use cp with the -r option
    cp -r "folder one/" "folder two/"
    I don't want to move all the files though. Is there another option?

  4. #4
    Linux Newbie
    Join Date
    Jan 2008
    Location
    UK
    Posts
    211
    You could use for example for C files;

    cp *.c "home/fred/folder one/"
    this copies only C files

  5. #5
    scm
    scm is offline
    Linux Engineer
    Join Date
    Feb 2005
    Posts
    1,044
    Quote Originally Posted by strinh View Post
    cp -m "//server1/directory 1/*.filetype" "//server2/directory 2/"

    I get the file not file error. Does anybody have any suggestions? Thanks in advance!
    Easiest way, if you have to have spaces in your filenames, is do the files individually:
    Code:
    for a in "/server1/directory 1/*.filetype"
    do
        cp -p "$a" "/server2/directory 2"
    done
    The -p preserves file ownerships and permissions, if you need to do that.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...