简体   繁体   中英

How to delete .jpg file in linux console

By accident I named my image file wrong so I wanted to delete it. So I typed the following in my linux console:

rm localapps\logo.jpg

But it didn't work.

Then I wrote

rm *.jpg

then it worked. Simple question. Why did the first not work , even I know that is the way to delete files in linux?

We would need the output of the commands you are running. You typically have no output when the command succeeds.

It is also important for you to notice that in linux, the / character is used to denote directories, and not \\ , which is actually typically the escape character.

In a terminal is also very important for you to notice in which directory are you working and what is the relative path to the file you want to refer to. You can find this out with the command pwd that stands for print working directory .

You would see something like

your-box:~ blurry$ pwd
/home/blurry
your-box:~ blurry$

This said, when you type

rm localapps\logo.jpg

since \\ is a escape character, this is interpreted as

rm localappslogo.jpg

this means, it is looking for the file named localappslogo.jpg in the current directory ( /home/blurry/localappslogo.jpg ).

I assume that file does not exist, then, it will output something like:

rm: localappslogo.jpg: No such file or directory

when you type

rm *.jpg

this code removes any file ending in .jpg in the current directory . So notice that if you were trying to delete a file that was in the localapps folder, you should use instead

rm localapps/logo.jpg

But this is always assuming that the relative path to your image is localapps/logo.jpg .

You can also change directory then delete the file like this,

cd localapps
rm logo.jpg

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM