Linux Tip: How to handle a files with a dash as first character from command line

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
Follow If Not True Then False Updates!
  1. Linux: Create Text File on Linux Shell / Command Line
  2. Linux locate command: Find Files and Directories Quickly and Efficiently
  3. Delete files permanently with shred command in Linux – Remove absolutely
  4. Google search from Linux and UNIX command line
  5. Linux: Display / Show File Contents (tabs, line breaks, non-printing characters)

Leave a Comment

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="" highlight="">

Bear