Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

when I tried to change file name from old.file(1).gz to new.file.gz, It says syntax error, I am using ubuntu 12.04.

mv old.file(1).gz new.file.gz
bash: syntax error near unexpected token `('
share|improve this question
6  
Try mv 'old.file(1).gz' new.file.gz. – yeti Apr 21 '14 at 8:34
    
what ubuntu is that? I've never heard of Ubuntu 12.0 – mojo706 Apr 21 '14 at 8:44
up vote 14 down vote accepted

Yeti's comment will work for you, but if you would like to know why, it's because parentheses are interpreted as special characters, and have to either be escaped with \ or the entire filename quoted (as above) [edit: sorry, only the ( and ) need to be quoted].

If you have tab completion enabled, just type the first few characters of the file name and hit tab. I.e., typing mv old and hitting tab, should turn into mv old.file\(1\).gz (unless there are other potential files that old* could refer to).

share|improve this answer
6  
The entire file name doesn't need quoting. Only the () do. You can do mv old.fil'e(1).'gz new.file.gz if you like. – Stéphane Chazelas Apr 21 '14 at 8:53
mv 'old.file(1).gz' new.file.gz

should fix the problem.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.