LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   how to delete a file name call "-D" (https://www.linuxquestions.org/questions/linux-newbie-8/how-to-delete-a-file-name-call-d-223377/)

henryluo 08-28-2004 01:15 AM

how to delete a file name call "-D"
 
how to rm "-D" file name ,thanks

Dark_Helmet 08-28-2004 01:17 AM

Use the cd command to enter the directory with the file, then execute:
Code:

rm ./-D

henryluo 08-28-2004 02:44 AM

thanks very much

barisdemiray 08-28-2004 11:41 AM

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

Code:

[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
[mbaris@slackware:~]$

There is always more than one way to do something in UNIX world ;-)

student04 08-28-2004 02:40 PM

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

Code:

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

Dark_Helmet 08-28-2004 02:58 PM

Actually, executing
Code:

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
Code:

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


All times are GMT -5. The time now is 08:32 PM.