Reputation: 621
I wanted to create a file called "-" through the command touch.
touch -
I expected an error or the creation of the file, however no error and no file creation.
Also, how can I create the file called "-". Is it even possible?
Upvotes: 3
Views: 3279
Reputation: 241988
As documented in man touch
:
A FILE argument string of - is handled specially and causes touch to change the times of the file associated with standard output.
To create a file of that name, use a longer path, e.g.:
touch ./-
To see the difference, try
( echo a ; sleep 2; ) > file ; date ; stat file
versus
( echo a ; sleep 2; touch - ) > file ; date ; stat file
In the first case, the modification time will be 2 seconds before the actual time. In the second case, it will be almost identical to it.
Upvotes: 3