terminal-logo-small

Sometimes you maybe have to handle files with a dash (-) as first character from Linux command line. It can be difficult, because the script “thinks” the marks after the dash are parameters.

So files which name begins with dash (-) can not be dealt with directly by typing the command and the file name, such as the following:


less -file-with-a-dash-as-first-character

Files which name begins with dash (-) can be used as follows:


less ./-file-with-a-dash-as-first-character

Real usage

Create a file named “-test”:


touch ./-test

Add some content to “-test” file:


echo "test content to file" > ./-test

View “-test” file content:


cat ./-test

Delete “-test” file:


rm ./-test