Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create a file with its name starting with dash in Linux? (ex "-file")

How can I create a file named "-file" using command line in Linux?

like image 832
sebthesaviour Avatar asked Nov 17 '16 08:11

sebthesaviour


People also ask

Can a file name start with a dash?

Sometimes you can slip and create a file whose name starts with a dash ( - ), like -output or -f. That's a perfectly legal filename.

How do I make a dash in Linux?

Press Option+Shift+hyphen . Linux desktop environment. Enable the Compose key (instructions for doing that vary depending on your flavor of Linux—for examples, see Linux Keyboard Shortcuts For Text Symbols). After the Compose key is enabled, you can create an em dash by typing the Compose key followed by three hyphens.

What is dashed file in Linux?

Dash (-) character at the end of the commands is a popular convention to refer stdin or stdout. Dash is not a special character for filesystem or kernel. When -- character seen, shell thinks that optional arguments for command itself finished and doesn't make option parsing anymore.


2 Answers

In bash -- is a flag that is interpreted as "nothing after this should be taken as a flag", so - is no longer parsed as an option.

touch -- -file
like image 169
karel Avatar answered Sep 29 '22 11:09

karel


specify a path in front of it, e.g. ./-file

like image 22
Stefan Hegny Avatar answered Sep 29 '22 12:09

Stefan Hegny