为什么rm命令不能删除文件? [英] Why does the rm command not remove the file?

查看:155
本文介绍了为什么rm命令不能删除文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我今天访问我的Ubuntu 16.04服务器并想要删除文件"test2"时,它根本没有被删除!

When i today accessed my Ubuntu 16.04 server and wanted to remove the file "test2" it was simply not deleted!

我用过

rm test2

以及

rm -f test2

但是它仍然没有将其删除,因为您可以在此处阅读:

but it still did not delete it as you can read here:

root@icinga:~# ls
basket  desd.save  packages  scripts  src  test2  test5  unused
root@icinga:~# rm test2
root@icinga:~# ls
basket  desd.save  packages  scripts  src  test2  test5  unused
root@icinga:~# rm -f test2
root@icinga:~# ls
basket  desd.save  packages  scripts  src  test2  test5  unused

我也试图删除其他文件,但是没有用!

I have also tried to remove other files, didn't work!

我是"test2"的所有者,使用 ls -la test2 可以看到我有权读写此文件!

I am the owner of "test2" and using ls -la test2 you can see that I have the rights to read and write this file!

root@icinga:~# ls -la test2
-rw-r--r-- 1 root root 9 Nov 11 20:33 test2

使用哪个rm 表示/bin/rm .

root@icinga:~# which rm
/bin/rm

\ rm test2 不会删除该文件!

我还检查了名称,在末尾没有空格等,因为当我使用 cat test2 时,会显示正确的内容!

I have also checked for the name, there are no spaces at the end etc. because when I use cat test2 the correct content is shown!

我也可以创建一个新文件,但也不能删除它.

I also can create a new file but can't delete this as well.

rm 也不是别名,我使用了 unalias rm ,但它说"rm:未找到".

rm is also not an alias, I used unalias rm but it said "rm: not found".

重新启动也无济于事.

我有一个问题,我不小心删除了一个文件而不是移动了它,所以我创建了一个脚本,该脚本只是将文件移动到某个目录.
然后,我使用了 nano/etc/environment ,并在此脚本所在的位置添加了:/root/scripts"!
之后,我使用 alias rms ='./rm'创建了别名rms.我知道将文件命名为系统命令可能是愚蠢的,我已经将其更改为删除!

I had the problem that I accidently deleted a file instead of moving it, so I created a script that simply moves the file to a certain directory.
Then I used nano /etc/environment and added ":/root/scripts" where this script was located!
After that i created the alias rms by using alias rms='./rm'. I know it might be dumb naming a file like a system command, I already changed it to remove!

但是在完成所有这些操作之后,出现了一个错误,即找不到rm,可以在以下软件包中找到rm:utils.所以我尝试apt-get install coreutils,但是它说已经安装了.
因此,我首先使用 touch/bin/rm ,然后使用 chmod + x/bin/rm .

But after doing all this there was the Error that rm can't be found and can be found in the following packages: coreutils. So i tried apt-get install coreutils but it said it is already installed.
So I first used touch /bin/rm and then chmod +x /bin/rm.

此问题发生后!

问题是/bin/rm 文件为空,所以我设置了虚拟机并将所需的文件复制到服务器!

the problem was the /bin/rm file was empty so I set up an virtual machine and copied the required file to the server!

推荐答案

要删除文件,您需要能够在包含该文件的目录中进行修改(写入).如果未删除文件,则您可能没有写该目录的权限.这可能是因为该文件位于只读文件系统上,但是更可能是您对该目录没有写权限.使用 rm -f 可以抑制错误消息(和提示).

To remove a file, you need to be able to modify (write) in the directory that contains the file. If the file isn't deleted, then you probably don't have permission to write on the directory. This could be because the file is on a read-only file system, but it is more likely that you do not have write permission on the directory. Using rm -f suppresses error messages (and prompts).

另一种可能性(这里可能不是这种情况)是文件名的末尾有空格或其他不可见字符,并且您指定为文件的名称实际上不存在(文件为" test2 "而不是" test2 ";或者可能是" test1< bs> 2 ",其中< bs> 表示退格,或者…有无数种方法来遇到问题.

One other possibility (probably not the case here), is that the file name has a space or other invisible character at the end, and the name you specify as a file doesn't actually exist (the file is "test2" and not "test2"; or maybe it is "test1<bs>2" where the <bs> represents a backspace, or … there are endless ways to run into problems).

重新运行 rm test2 ;响应提示;查看错误消息.

Rerun rm test2; respond to the prompt; look at the error messages.

或在包含文件的目录中运行 ls -ld.并查看权限,但是请记住,ACL(访问控制列表)和扩展属性会使您更难确定您的权限是(尽管同样,它们不太可能成为问题的一个因素).

Or run ls -ld . in the directory containing the file and look at the permissions, but remember that ACLs (access control lists) and extended attributes can make it harder to work out what your permissions are (though again, they're unlikely to be a factor in the problem).

这篇关于为什么rm命令不能删除文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆