简体   繁体   English

如何在Linux控制台中删除.jpg文件

[英]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: 因此,我在Linux控制台中输入了以下内容:

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? 为什么第一个不起作用,甚至我都知道这是在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. 还需要注意的是,在Linux中, /字符用于表示目录,而不是\\ ,实际上是转义字符。

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 . 您可以使用代表打印工作目录的命令pwd来查找。

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 ). 这意味着它将在当前目录( /home/blurry/localappslogo.jpg )中查找名为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 . 此代码删除当前目录中所有以.jpg结尾的文件。 So notice that if you were trying to delete a file that was in the localapps folder, you should use instead 因此请注意,如果您尝试删除localapps文件夹中的文件,则应改用

rm localapps/logo.jpg

But this is always assuming that the relative path to your image is localapps/logo.jpg . 但这总是假设图像的相对路径是localapps/logo.jpg

You can also change directory then delete the file like this, 您还可以更改目录,然后像这样删除文件,

cd localapps
rm logo.jpg

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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