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
  • 68,507

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,236
  • 4
  • 48
  • 98
snoop
  • 4,040
  • 9
  • 40
  • 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,153
  • 2
    +1 for mentioning tab completion. And don't forget that you can hit Tab more than once When I have a file with a name like "Doctor Who - S20E03 (125) - Mawdryn Undead - Parts 1-4 (The Guardian Trilogy 1)", it would be really tedious to type all the backslashes needed for that filename. But I hit Tab, and get "Doctor\ Who\ -\ S". Then I type "20E03", hit Tab again, and get the rest of the filename, all correctly backslash-escaped. – rmunn Oct 05 '15 at 01:21
  • Thx .. this worx also very well ... hhh .. i am a littlebit new in ubuntu ... thx it is verry usefull :D – Martin Šanta Oct 06 '15 at 08:29
  • @MartinŠanta, remember you can also mark an answer "accepted" by clicking the checkmark to the left. That way the question no longer appears as an "unanswered question" in search results. :) See http://askubuntu.com/help/someone-answers – Wildcard Oct 25 '15 at 13:45
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
  • 43,546
  • 8
  • 97
  • 150