Welcome to the most active Linux Forum on the web.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 08-28-2004, 01:15 AM   #1
Registered: Nov 2003
Posts: 36

Rep: Reputation: 15
how to delete a file name call "-D"

how to rm "-D" file name ,thanks
Old 08-28-2004, 01:17 AM   #2
Senior Member
Registered: Jan 2003
Posts: 2,786

Rep: Reputation: 373Reputation: 373Reputation: 373Reputation: 373
Use the cd command to enter the directory with the file, then execute:
rm ./-D
Old 08-28-2004, 02:44 AM   #3
Registered: Nov 2003
Posts: 36

Original Poster
Rep: Reputation: 15
thanks very much
Old 08-28-2004, 11:41 AM   #4
Registered: Sep 2003
Location: Ankara/Turkey
Distribution: Slackware
Posts: 155

Rep: Reputation: 30
Just an alternative way..
You can't delete the files beginning with `-' because it will be processed as a command line option wrongly. So you can use `--' switch to tell the program that there will be no command line option anymore, as in

[mbaris@slackware:~]$ touch -- -butterfly
[mbaris@slackware:~]$ rm -butterfly
rm: invalid option -- b
Try `rm --help' for more information.
[mbaris@slackware:~]$ rm -- -butterfly
rm: remove regular empty file `-butterfly'? y
There is always more than one way to do something in UNIX world ;-)
Old 08-28-2004, 02:40 PM   #5
Registered: Jan 2004
Location: Georgia
Distribution: OS X, CentOS
Posts: 669

Rep: Reputation: 34
or you can rename it, and then delete it.. (more effort, but another way :-D )

mv -D.jpg picture.jpg
rm -f picture.jpg
(there isn't a renaming command in linux, so you just move it to the same directory, giving it a new name
Old 08-28-2004, 02:58 PM   #6
Senior Member
Registered: Jan 2003
Posts: 2,786

Rep: Reputation: 373Reputation: 373Reputation: 373Reputation: 373
Actually, executing
mv -D.jpg picture.jpg
results in the same original problem. The mv command interprets "-D.jpg" as an option; not as a filename. It would work if you prefixed the -D with the current directory path ./ or the absolute path. That, however, would basically just work it's way back to a plain rm command.

And, just for a little info, there is a rename command. It's slightly different than what you might expect. You give rename specific text to replace, the text to replace it with, and then a list of files to perform the substitution on. For example
rename jpg jpeg *.jpg
That will rename every file in the current directory that ends with .jpg to end with jpeg. It will also replace jpg with jpeg if found within the filename itself. In other words, pic01.jpg will be renamed pic01.jpeg. vacation_jpg.jpg would be renamed vacation_jpeg.jpeg

You can read all about it with man rename


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
oops - made a file called "--dereference" - how do I delete it? BrianK Linux - General 2 06-21-2004 08:37 PM
How do you delete a file called "--tape-lengh=1"? I've tried everything... Huddlebum Linux - General 1 01-01-2004 10:11 PM
Can't locate object method "splitpath" via package "File::Spec" RobJohnston Linux - General 2 06-28-2003 09:59 AM
"Function not implemented" error in call to "sem_open()" Krishnendu8 Linux - Newbie 1 06-07-2003 02:52 AM
"Function not imlemented" error in call to "sem_open()" Krishnendu8 Linux - Networking 0 06-07-2003 02:19 AM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 07:34 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration