Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!


Click here to return to the 'Easier ways' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Easier ways
Authored by: gidds on Jul 31, '02 09:30:54AM
That's a very convoluted way of doing it.
For the specific case of a leading hyphen, as has been said elsewhere, most Unix commands have a neat way around it: if you give -- as a parameter, then all following parameters are taken as filenames and not as parameters.  So
rm -- -myfile
does the trick very easily, as does
rm ./-myfile
For other awkward or unprintable characters, it's often easier to identify the file using the filename completion features built into the shell.  If your file is called myfile^?, say, and it's the only one beginning with myfile, then
rm myfile*
could hardly be easier.  If the file is harder to separate out, you can use characters after the *, or instead use one or more of the ? wildcard which matches a single character.  You can ensure you're only deleting the right file by trying
ls (whatever)
before doing the
rm (whatever)


[ Reply to This | # ]
Easier ways
Authored by: macsforever2000 on Jul 31, '02 11:24:57AM

My favorite way is to use the -i modifier and a name close to the desired one.

In this case:

rm -i *myfile

Then is goes through all matching files and asks if you want to delete them.



[ Reply to This | # ]
Easier ways
Authored by: ber on Jul 31, '02 04:49:32PM

-i is useful but needs to be used with gidd's suggestions or you fall into the same trap.

sh-2.05a$ rm -i -x
rm: illegal option -- x
usage: rm [-f | -i] [-dPRrvW] file ...
unlink file
sh-2.05a$ rm -i ./-x
remove ./-x?



[ Reply to This | # ]
Easier ways
Authored by: DavidRavenMoon on Jul 31, '02 06:57:46PM

Or ... just drag it to the Trash! (Cmd-Del) How novel! ;)

[ Reply to This | # ]

Easier ways
Authored by: bluehz on Jul 31, '02 11:42:53PM

Thnx Gidds - that is much easier - plus the code above got mucked up on its way to the posting....



[ Reply to This | # ]