Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to open a "-" dashed filename using terminal?

Tags:

linux

terminal

I tried gedit, nano, vi, leafpad and other text editors , it won't open, I tried cat and other file looking commands, and I ensure you it's a file not a directory!

like image 738
Alfran Avatar asked Feb 12 '17 12:02

Alfran


People also ask

Can a filename start with a dash?

Don't start or end your filename with a space, period, hyphen, or underline. Keep your filenames to a reasonable length and be sure they are under 31 characters.

What is dashed file name?

In Unix or Linux operating systems, working with dashed filename requires some attention. In some cases, you may need to handle files with a dash (-) as the first character. Because dash (-) is generally used by commands to specify options and arguments.


4 Answers

This type of approach has a lot of misunderstanding because using - as an argument refers to STDIN/STDOUT i.e dev/stdin or dev/stdout .So if you want to open this type of file you have to specify the full location of the file such as ./- .For eg. , if you want to see what is in that file use cat ./-

like image 160
Prithvi Raj Avatar answered Oct 19 '22 14:10

Prithvi Raj


Both cat < - and ./- command will give you the output

like image 45
mapmalith Avatar answered Oct 19 '22 15:10

mapmalith


you can use redirection

cat < -file_name

like image 6
wyx Avatar answered Oct 19 '22 14:10

wyx


It looks like the rev command doesn't treat - as a special character.

From the man page

The rev utility copies the specified files to standard output, reversing the order of characters in every line.

so rev - | rev

should show what's in the file in the correct order.

like image 5
michfuer Avatar answered Oct 19 '22 14:10

michfuer