2

I am playing with FTP via the command line, and I get two problems. I am not able to rename or enter folders like:

dir /home/folder1/Human (2012)

I tried:

cd ~/folder1/Human\ (2012)

Here I receive a message that the folder does not exist.

mv ~/folder1/Human\ (2012)

In this case, I receive a message that says:

syntaxfailure at (

How can I solve this problem?

pomsky
  • 70,557

3 Answers3

11

You could double quote your path:

cd ~/"folder1/Human (2012)"

or you should provide escape sequence for (,) and (space) (as these are special characters):

cd ~/folder1/Human\ \(2012\)

and

mv ~/"folder1/Human (2012)"

With escape sequence:

mv ~/folder1/Human\ \(2012\)
wjandrea
  • 14,504
snoop
  • 4,110
  • 9
  • 41
  • 58
8

You have the right idea with the \ before the space. That applies to all special characters—parentheses included. Put a backslash before the open paren and another backslash before the close paren and it will work.

Tab completion is helpful in these cases...if you start typing the filename and then press Tab, it will auto-complete the rest of the filename, inserting backslashes where necessary. (If you haven't typed enough of the filename for it to be unambiguous which file you mean, bash will still autocomplete as much of the filename as it can. Pressing tab twice will show a list of possible completions of the filename.)

Wildcard
  • 1,260
2

I agree with snoop that the way to do this is to use " marks when you specify a file or directory.

However, if there are a whole bunch of directories that need to be renamed, you can use rename to rename them to friendlier names. Rename works similar to sed except rename renames files and directories whereas sed is usually used to edit the contents of files. Here is an example:

rename 's/ //g;s/\(//g;s/\)//g' ~/folder1/*

So, if you had the following directories located in ~/folder1:

Human (2012)
Human (2011)
Human (2010)

they will be renamed to this instead:

Human2012
Human2011
Human2010

Run the following command for more information:

man rename
mchid
  • 44,904
  • 8
  • 102
  • 162