cat: illegal option -- 2 while merging

wlan-141056:part_u_2 prova$ ls
-2e-5_cas 0_cas     10e-5_cas 20e-5_cas 40e-5_cas 5e-5_cas
wlan-141056:part_u_2 prova$ cat -2e-5_cas 0_cas > prova
cat: illegal option -- 2 usage: cat [-benstuv] [file ...]

What's wrong with merging two files using cat ?


Solution 1:

The first file you want to cat starts with a - so cat considers it to be an option. But as there is no option 2 (see the usage string) it throws an error.

Use one of

cat ./-2e-5_cas 0_cas > prova
cat -- -2e-5_cas 0_cas > prova

instead (the second is better for scripts etc).

PS: In general it is recommend to not use - as the first character of a filename to prevent exactly these issues.