Never been to TextSnippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world (or not, you can keep them private!)

delete a filename starting with a dash (See related posts)

Have you ever created a file by mistakenly adding a flag where you shouldn't? Find the inode number of the file and delete it using find:

[one:~/src/oops] ryanschwartz$ cp test -p
[one:~/src/oops] ryanschwartz$ ls
-p test
[one:~/src/oops] ryanschwartz$ rm -p
rm: illegal option -- p
usage: rm [-f | -i] [-dPRrvW] file ...
unlink file
[one:~/src/oops] ryanschwartz$ \rm -p
rm: illegal option -- p
usage: rm [-f | -i] [-dPRrvW] file ...
unlink file
[one:~/src/oops] ryanschwartz$ ls -li
total 0
5937393 -rw-r--r-- 1 ryanschwartz textdrive - 0B May 27 18:04 -p
5937392 -rw-r--r-- 1 ryanschwartz textdrive - 0B May 27 18:04 test
[one:~/src/oops] ryanschwartz$ find . -inum 5937393
./-p
[one:~/src/oops] ryanschwartz$ find . -inum 5937393 -exec rm {} \;
[one:~/src/oops] ryanschwartz$ ls -li
total 0
5937392 -rw-r--r-- 1 ryanschwartz textdrive - 0B May 27 18:04 test

Comments on this post

jason posts on May 27, 2005 at 18:18
Gotta embed that code in code tags.
mattg posts on May 27, 2005 at 22:11
You could also try using "--"

from the man page:

The rm command uses getopt to parse its arguments, which allows it to accept the `--' option which will cause it to stop processing flag options at that point. This will allow the removal of file names that begin with a dash (`-'). For example:

rm -- -filename
nickstenning posts on May 31, 2005 at 22:38
I would agree with mattg, why not just
rm -- -p
, or *even* easier, just
rm ./-p
?

You need to create an account or log in to post comments to this site.


Related Posts