I'm trying to use smbclient in a bash script to make a directory on a remote windows server.

Whilst this works:

smbclient -U "DOMAIN/$username" "//remoteserver/folder with spaces" --directory "Another folder with spaces/" -c "mkdir /newfolder/"

This doesn't:

smbclient -U "DOMAIN/$username" "//remoteserver/folder with spaces" --directory "Another folder with spaces/" -c "mkdir /folder to create with spaces/"

Instead a folder simply called 'folder' is created. I've tried many variations like the following:

"mkdir /folder\ to\ create\ with\ spaces/"
"mkdir '/folder to create with spaces/'"
'mkdir '/folder to create with spaces/''

but can't seem to find the magic combination.

  • The escape char isn't /, it is \. So give mkdir '/folder\ to\ create\ with\ spaces' a try.
    – Panki
    Apr 9, 2019 at 11:46
  • Apologies - mistake in my question write up - I did try \ not / - question updated. Apr 9, 2019 at 11:56
  • What is the difference supposed to be between the 2nd and the 4th? (-:
    – JdeBP
    Apr 9, 2019 at 12:53
  • Ooops! :) edited Apr 9, 2019 at 13:28

1 Answer 1


These options should work:

  • -c 'mkdir "folder to create with spaces"'
  • -c "mkdir \"folder to create with spaces\""
  • That's worked great thanks :) Apr 9, 2019 at 13:27
  • How do you escape a " in a filename, I didn't find how to do it...
    – Fravadona
    Dec 10, 2021 at 21:03

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.