Less – How to ‘less’ a File Named ‘-‘?

lessstdin

I accidentally created a file with the name - (eg, seq 10 > -). Then I tried to use less to view it, but it just hangs.

I understand that this is happening because less - expects input from stdin, so it does not interpret the - as a file name. I tried less \- but it does not work either.

So, is there any way to indicate less that - is a file and not stdin?

The best I could get is:

find -name '-' -exec less {} +

Best Answer

Just prefix it with ./:

less ./-

Or use redirection:

less < -

Note that since - (as opposed to -x or --foo-- for instance) is considered a special filename rather than an option, the following doesn't work:

less -- -   # THIS DOES NOT WORK
Related Question