Results 1 to 4 of 4

Thread: Copy Files with the Command Line - Error Using Parentheses

  1. #1
    Join Date
    May 2011
    Location
    Tejas
    Beans
    18
    Distro
    Ubuntu 10.10 Maverick Meerkat

    Copy Files with the Command Line - Error Using Parentheses

    How do you copy files with () in the name using the command line?

    eg. = cp my (file) name.txt /home/user/Documents

    result = -sh: syntax error: "(" unexpected

    I know you have to put "\" before a space in the file name, but what do you do about parentheses in the file name?

  2. #2
    Join Date
    Jul 2007
    Location
    Poland
    Beans
    4,499
    Distro
    Ubuntu 14.04 Trusty Tahr

    Re: Copy Files with the Command Line - Error Using Parentheses

    you can try using \ to escape () too, but it would be easier to put the name in quotes "" or '' (now you wont have to manage spaces either)

    besides try autocompletion - type first few chars, press tab and the name should be expanded to its full form, with all the necessary escaping done for you, as long as there is no ambiguosity.
    if your question is answered, mark the thread as [SOLVED]. Thx.
    To post code or command output, use [code] tags.
    Check your bash script here // BashFAQ // BashPitfalls

  3. #3
    Join Date
    Feb 2009
    Location
    Dallas, TX
    Beans
    7,790
    Distro
    Ubuntu 16.04 Xenial Xerus

    Re: Copy Files with the Command Line - Error Using Parentheses

    Quote Originally Posted by famulusmercury View Post
    what do you do about parentheses in the file name?
    Hi famulusmercury.

    You can do the same, and escape them:
    Code:
    mv myfile\(2012\).txt /tmp
    or you can use quotes:
    Code:
    mv "myfile(2012).txt" /tmp
    Let us know how it goes.
    Regards.

  4. #4
    Join Date
    May 2011
    Location
    Tejas
    Beans
    18
    Distro
    Ubuntu 10.10 Maverick Meerkat

    Re: Copy Files with the Command Line - Error Using Parentheses

    That got it. Thanks!

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •