2

I have a directory on my FreeBSD server whose contents are created by Windows users over Samba. The filenames and paths within it sometimes contain spaces, as is common in the Windows world.

I just tried to delete some files in a subdir which had been duplicated.

  • rm -v "New folder (1)/*" failed using both single+double quotes ("no such dir or file")
  • rm -v New\ folder\ \(1\)/* succeeded

I thought that spaces in paths could be handled by putting the path within quotes. If I'm copy/pasting the path then I would find it easier to add quotes than to manually escape every space or other special character in it.

What do I need to do, to get the first example to work correctly?

3

When you put the * in quotes then it's treated as a quoted character so it must be placed outside the quotes where it will be treated by the shell.

rm -v "New folder (1)"/*

  • Does that mean that "my folder/"r*.fr?, "my fol"der/r*.fr?, "my"\ "folder/r"*.fr? and "my folder/r"*".fr"? are all allowed and identical? Or are there important but non-obvious restrictions that apply to using wildcards this way?? – Stilez Oct 27 '17 at 13:38
  • @Stilez I made a correction. The slash, too, needs to be outside the quotes – Rob Oct 27 '17 at 13:45
  • Thanks. Can you clarify though, what part(s) of a path+filename can/cannot be inside or outside the quotes, in this kind of use? For example, if the "/" must be outside quotes, what about "my folder"/"my file"*, or other cases where the filename also has spaces? And other more contrived examples such as "my"\ "folder"/*"-2017 data.txt"? (I'd look it up but no idea where to find info on it, or what to search under, for the details) – Stilez Oct 27 '17 at 13:48
  • It makes no difference if / is inside or outside quotes. – Satō Katsura Oct 27 '17 at 14:26

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.