Find the answer to your Linux question:
Results 1 to 7 of 7
Someone crated a file with starting "--" as starting file_name. I have "--file-name", with no GUI; all commands I tried to operate this file return with error since they interpret ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined! legendbb's Avatar
    Join Date
    Mar 2007
    Location
    Canada
    Posts
    27

    How to deal with file starting with"--"


    Someone crated a file with starting "--" as starting file_name.

    I have "--file-name", with no GUI; all commands I tried to operate this file return with error since they interpret this "--" as argument tag.

    Tried to use quote, doesn't help.

    For curiosity, how to deal with it?

    Thanks,

  2. #2
    Trusted Penguin Irithori's Avatar
    Join Date
    May 2009
    Location
    Munich
    Posts
    3,218
    - escape the - with \
    - the -print0 of the find command also helps
    - ls -i shows the inode, which then could be used to do operations on the file
    You must always face the curtain with a bow.

  3. #3
    Just Joined! legendbb's Avatar
    Join Date
    Mar 2007
    Location
    Canada
    Posts
    27

    Cool

    # mv \--index.html index.html
    mv: unrecognized option `--index.html'

    could not get "\" to work, but I found a walk around by just using absolute path.

    Thanks,

  4. #4
    Trusted Penguin Irithori's Avatar
    Join Date
    May 2009
    Location
    Munich
    Posts
    3,218
    Ah sorry. There is a much easier way.

    You can tell the commands (probably not all, so be carefull), that there wont be any more options by giving a --
    Code:
    touch -- --index.html
    ls -la -- --index.html
    mv -- --index.html index.html
    ls -la -- index.html
    You must always face the curtain with a bow.

  5. #5
    Trusted Penguin
    Join Date
    May 2011
    Posts
    4,307
    and if you're lazy and don't want to read man pages - open up nautilus, browse to the file and do whatever with it...

  6. #6
    Just Joined!
    Join Date
    Aug 2011
    Posts
    35
    you could also use quotes for example cp "--myfile" "destination"

  7. #7
    Just Joined!
    Join Date
    Aug 2011
    Posts
    7
    I don't think this works. Putting an option in quotes still leaves it the same option. It will complain that --myfile is not a valid option. Whereas
    Code:
    cp -- --myfile destination
    will work, because it tells cp that everything after the -- is not an option.

Posting Permissions

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