Linux Tip: How to handle a files with a dash as first character from command line - Comment Page: 1

Sometimes you maybe have to handle files with a dash (-) as first character from Linux command line. It can be difficult, because the script "thinks" the marks after the dash are parameters. So files which name begins with dash (-) can not be dealt with directly by typing the command and the file name, such as the following: less -file-with-a-dash-as-first-character Files which name begins with dash (-) can be used as follows: less ./-file-with-a-dash-as-first-character Real usage Create a file named "-test": touch ./-test Add some content to "-test" file: echo "test content to file" > ./-test View "-test" file content: cat ./-test Delete "-test"...

2 comments on “Linux Tip: How to handle a files with a dash as first character from command line - Comment Page: 1

    1. thx, that’s tricky..

      Reply
    2. Many (all?) commands have “–” parameter, which means “end of parameters”. So you can use
      command — -file-with-a-dash

      Reply

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Close