4

I don't know why but when I go to change this file name with mv command it comes up with the error stating not a directory.

-bash-4.1# mv {{ THEME SANITIZED }}.hacks.css myomega.hacks.css

  • Do you have spaces in your file name? – Ramesh Mar 27 '14 at 1:18
4

mv "{{ THEME SANITIZED }}.hacks.css" myomega.hacks.css will work.

  • have to wait 6 minutes to give you the answer which is stupid! – cea Mar 27 '14 at 1:23
  • Glad it worked :) No problem :) – Ramesh Mar 27 '14 at 1:24
2

You need to tell the shell that you mean for the braces and spaces to be part of the file name, instead of being interpreted as shell syntax.

You can type file names containing special characters inside single quotes. This works for every character except the single quote itself. This is the easiest method in a script.

mv '{{ THEME SANITIZED }}.hacks.css' myomega.hacks.css

If you need a single quote inside a single-quoted string, you can use the four-character sequence '\''.

mv 'It'\'s' wierd' this_is_weird

Alternatively, you can put a backslash before any character, which makes it lose its special meaning. It doesn't hurt to put a backslash before characters that have no special meaning, but it's of course extra unnecessary typing.

mv \{\{\ THEME\ SANITIZED\ \}\}.hacks.css myomega.hacks.css

If the file name comes from a variable, use double quotes around the variable expansion to preserve special characters (with a bare variable as in mv $source $destination, some special characters in the value of the variable are expanded).

source='{{ THEME SANITIZED }}.hacks.css'
destination=myomega.hacks.css
mv "$source" "$destination"

On the command line, the easiest way to type such a file name is to rely on completion. You'll need to enter at least the first character, then press Tab.

mv \{Tab
mv \{\{\ THEME\ SANITIZED\ \}\}.hacks.css 

1

you can use double quotes to scape or scape with slash like for example:
using double quotes:

mv "{{ THEME SANITIZED }}.hacks.css" myomega.hacks.css

using slash:

mv \{\{\ THEME\ SANITIZED\ \}\}.hacks.css myomega.hacks.css

something cool that some people doesn't know how to remove ou rename a directory when it's start with dash you can you dash dash :D
exemple:

mkdir -directory_with_dash
rm -r -- -directory_with_dash
  • Interesting. Where would I find such information in a book- does this pertain to LINUX only? – cea Mar 27 '14 at 3:47

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.