InfoHeap
Tech
Navigation
  • Home
  • Tutorials
    • CSS tutorials & examples
    • CSS properties
    • Javascript cookbook
    • Linux/Unix Command Line
    • Mac
    • PHP
      • PHP functions online
      • PHP regex
    • WordPress
  • Online Tools
    • Text utilities
    • Online Lint Tools
search

Linux/Unix Command Line tutorials

  • Awk
  • Curl
  • Edit a file without changing its timestamp on Linux
  • Find which process is listening on a port on Linux
  • Get file size in bytes on Linux
  • How to delete files starting with dash/hyphen
  • How to kill unresponsive ssh session using escape sequence
  • How to show environment variable for a process id (pid)
  • How to sort using a specific field on Linux
  • How to specify environment variable for a command on Linux
  • How to zip/unzip a directory with password
  • ImageMagick
  • Impact on LC_ALL on Linux sort
  • Linux - find listening ports
  • Linux - find top directories by used disk size (excluding size of subdirectories)
  • Linux - how to run a command as different user
  • Linux - list only directories
  • Linux - providing sudo access to a users - some best practices
  • Linux - sending mail from command using mailutils
  • Linux file timestamps
  • Linux how to modify a user using usermod
  • Linux ping a port using netcat
  • Linux replace comma with newline
  • Linux screen - quick start guide
  • Linux what package provides a file
  • Linux/Unix - How to go to previous directory
  • Linux/Unix - find inode number of a file
  • Linux/Unix - truncate a large log file without deleting it
  • Linux/Unix history with date and time
  • Memcache - how to dump all keys and values on command line
  • Mongo - cli quick start guide
  • Perl command line - replace multi line comments
  • Python/Perl/Unix one liners
  • Rsync
  • Ruby gem - handy reference
  • SSH
  • Some handy linux gnu date commands
  • Use watch to monitor a command at some frequency on Linux
  • bower - installation and quick start guide
  • csvkit - parse csv file and data on Linux command line
  • ffmpeg
  • grep without regex (fixed string)
  • redis cli quick start tutorial
  • wget handy commands

Linux find

  • Find recently modified files on Linux
  • Linux - find and delete files older than 30 days
  • Linux - find files containing specific text
  • Linux find - ignore case in name
  • find - exclude directory or file pattern
 
  • Home
  • > Tutorials
  • > Linux/Unix Command Line

How to delete files starting with dash/hyphen

By admin on Oct 3, 2015

Deleting files starting with dash or hyphen can be little tricky as dash is interpreted as option prefix on Mac and Linux. Here is what happens when we try to delete file starting with dash on Ubuntu Linux:

$ echo "foo" > -file1.txt
$ ls -l
total 4
-rw-rw-r-- 1 user1 uer1 4 Oct  3 06:26 -file1
$ rm -file1.txt
rm: invalid option -- 'l'
Try 'rm ./-file1.txt' to remove the file ‘-file1.txt’.
Try 'rm --help' for more information.

The trick is to use double-dash -- to specify end of command options. To delete -file1.txt we can run the following command:

$ rm -- -file1.txt

In case you want to rename the file, you can run mv as shown below:

$ mv -- -file1.txt file1.txt
$ ls -l 
total 4
-rw-rw-r-- 1 user1 user1 4 Oct  3 06:32 file1.txt

Suggested posts:

  1. Gmail – how to find large size emails
  2. Jenkins how to clone a project
  3. mac pkgutil – quick start guide
  4. Iterate over specific file extension in a dir in shell script
  5. How to fix a broken sudoers file on AWS/EC2 Linux
  6. Linux – how to run a command as different user
  7. Linux – how to create a large file like 1GB
  8. How to locally override website domain (or hostname) to IP mapping
Share this article: share on facebook share on linkedin tweet this submit to reddit
Posted in Tutorials | Tagged Linux, Linux/Unix Command Line, Mac, Tutorials
  • Browse content
  • Article Topics
  • Article archives
  • Contact Us
Popular Topics: Android Development | AngularJS | Apache | AWS and EC2 | Bash shell scripting | Chrome developer tools | Company results | CSS | CSS cookbook | CSS properties | CSS Pseudo Classes | CSS selectors | CSS3 | CSS3 flexbox | Devops | Git | HTML | HTML5 | Java | Javascript | Javascript cookbook | Javascript DOM | jQuery | Kubernetes | Linux | Linux/Unix Command Line | Mac | Mac Command Line | Mysql | Networking | Node.js | Online Tools | PHP | PHP cookbook | PHP Regex | Python | Python array | Python cookbook | SEO | Site Performance | SSH | Ubuntu Linux | Web Development | Webmaster | Wordpress | Wordpress customization | Wordpress How To | Wordpress Mysql Queries | InfoHeap Money

Copyright © 2025 InfoHeap.

Powered by WordPress