Results 1 to 6 of 6
How can I specify filenames starting with a dash "-" on the command line? Most apps like cp and touch interpret anything starting with a dash as an option....
- 10-31-2006 #1Just Joined!
- Join Date
- Apr 2006
- Posts
- 97
Command line: filenames starting with -
How can I specify filenames starting with a dash "-" on the command line? Most apps like cp and touch interpret anything starting with a dash as an option.
- 10-31-2006 #2
Have you tried putting quotes around the filename?
Registered Linux user #388328 || Registered LFS user #15880
AMD 64 X2 4600+ :: 2X1GB DDR2 800 :: GeForce 9400 GT 512MB :: ASUS M2N32 Deluxe :: 4X250GB SATAII
Need instant help? Try us on IRC -- #linuxforums on freenode
- 10-31-2006 #3
Most commands allow you to explicitly end the options with --. So to copy --foo to bar:
Code:cp -- --foo bar
Flies of a particular kind, i.e. time-flies, are fond of an arrow.
Registered Linux User #408794
- 10-31-2006 #4Just Joined!
- Join Date
- Apr 2006
- Posts
- 97
Using quotes doesn't work, because Bash and most other shells I guess remove the quotes when the arg is passed. I even tried:
But then the filename actually has quotes around it.Code:touch "\"-a\""
Using the double dash did the trick:
I guess we just have to hope and pray that enough programs use the double-dash terminator. Thanks for the help.Code:touch -- -a
- 11-01-2006 #5Linux Engineer
- Join Date
- Apr 2006
- Location
- Saint Paul, MN, USA / CentOS, Debian, Solaris, SuSE
- Posts
- 1,117
Hi.
And one very old method ... cheers, drl
Resulting in:Code:#!/bin/sh # @(#) s1 Demonstrate one method to delete leading-dash filenames. echo echo " Creating file with leading dash." echo hi > -t1 echo " Files currently extant:" ls echo echo " Attempt to remove -t1:" rm -t1 echo echo " Remove by prefixing with ./" rm ./-t1 echo " Files now here:" ls
Code:% ./s1 Creating file with leading dash. Files currently extant: -t1 s1 Attempt to remove -t1: rm: invalid option -- t Try `rm --help' for more information. Remove by prefixing with ./ Files now here: s1
Welcome - get the most out of the forum by reading forum basics and guidelines: click here.
90% of questions can be answered by using man pages, Quick Search, Advanced Search, Google search, Wikipedia.
We look forward to helping you with the challenge of the other 10%.
( Mn, 2.6.n, AMD-64 3000+, ASUS A8V Deluxe, 1 GB, SATA + IDE, Matrox G400 AGP )
- 11-01-2006 #6Just Joined!
- Join Date
- Apr 2006
- Posts
- 97
Ah, that method is good! I can just prefix with ./, easy. Thanks.


Reply With Quote