Linux

另一個’rm:無法刪除’文件’:權限被拒絕`

  • August 23, 2018

我想.html/home/user1/html/目錄中刪除文件。

我已經嘗試了無數其他網站上發布的幾乎所有解決方案。沒有任何工作。

user1@comp1:~/html$ sudo rm -f .html
rm: cannot remove '.html': Permission denied

目錄屬性:

user1@comp1:~$ ls -al
total 0
drwxrwxrwx 1 user1 user1 4096 Aug 21 14:48 html

文件屬性:

user1@comp1:~/html$ ls -al
total 3912
-rwxrwxrwx 0 user1 user1 1365246 Aug 20 17:20 .html

我在目錄上嘗試過的東西(全部成功執行):

sudo chown $USER:$USER ./html
sudo chmod 777 ./html
sudo chmod -R 777 ./html

我在文件上嘗試過的東西(全部成功執行):

sudo chown $USER:$USER .html
sudo chmod 777 .html
sudo chmod 777 .

我嘗試查看文件的屬性(未成功執行):

user1@comp1:~/html$ lsattr .html
lsattr: Inappropriate ioctl for device While reading flags on .html

strace用須藤:

user1@comp1:~/html$ strace sudo rm -f .html
execve("/usr/bin/sudo", ["sudo", "rm", "-f", ".html"], [/* 17 vars */]) = -1 EPERM (Operation not permitted)
write(2, "strace: exec: Operation not perm"..., 38strace: exec: Operation not permitted
) = 38
exit_group(1)                           = ?
+++ exited with 1 +++

strace沒有須藤:

user1@comp1:~/html$ strace rm -f .html
execve("/bin/rm", ["rm", "-f", ".html"], [/* 17 vars */]) = 0
brk(NULL)                               = 0x805000
access("/etc/ld.so.nohwcap", F_OK)      = -1 ENOENT (No such file or directory)
access("/etc/ld.so.preload", R_OK)      = -1 ENOENT (No such file or directory)
open("/etc/ld.so.cache", O_RDONLY|O_CLOEXEC) = 3
fstat(3, {st_mode=S_IFREG|0644, st_size=39157, ...}) = 0
mmap(NULL, 39157, PROT_READ, MAP_PRIVATE, 3, 0) = 0x7fcfcb47e000
close(3)                                = 0
access("/etc/ld.so.nohwcap", F_OK)      = -1 ENOENT (No such file or directory)
open("/lib/x86_64-linux-gnu/libc.so.6", O_RDONLY|O_CLOEXEC) = 3
read(3, "\177ELF\2\1\1\3\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0P\t\2\0\0\0\0\0"..., 832) = 832
fstat(3, {st_mode=S_IFREG|0755, st_size=1868984, ...}) = 0
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fcfcb470000
mmap(NULL, 3971488, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7fcfcae30000
mprotect(0x7fcfcaff0000, 2097152, PROT_NONE) = 0
mmap(0x7fcfcb1f0000, 24576, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x1c0000) = 0x7fcfcb1f0000
mmap(0x7fcfcb1f6000, 14752, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x7fcfcb1f6000
close(3)                                = 0
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fcfcb460000
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fcfcb450000
arch_prctl(ARCH_SET_FS, 0x7fcfcb460700) = 0
mprotect(0x7fcfcb1f0000, 16384, PROT_READ) = 0
mprotect(0x60d000, 4096, PROT_READ)     = 0
mprotect(0x7fcfcb425000, 4096, PROT_READ) = 0
munmap(0x7fcfcb47e000, 39157)           = 0
brk(NULL)                               = 0x805000
brk(0x826000)                           = 0x826000
open("/usr/lib/locale/locale-archive", O_RDONLY|O_CLOEXEC) = 3
fstat(3, {st_mode=S_IFREG|0644, st_size=1668976, ...}) = 0
mmap(NULL, 1668976, PROT_READ, MAP_PRIVATE, 3, 0) = 0x7fcfcb28d000
close(3)                                = 0
ioctl(0, TCGETS, {B38400 opost isig icanon echo ...}) = 0
newfstatat(AT_FDCWD, ".html", {st_mode=S_IFREG|0777, st_size=1365246, ...}, AT_SYMLINK_NOFOLLOW) = 0
unlinkat(AT_FDCWD, ".html", 0)          = -1 EACCES (Permission denied)
open("/usr/share/locale/locale.alias", O_RDONLY|O_CLOEXEC) = 3
fstat(3, {st_mode=S_IFREG|0644, st_size=2995, ...}) = 0
read(3, "# Locale name alias data base.\n#"..., 4096) = 2995
read(3, "", 4096)                       = 0
close(3)                                = 0
open("/usr/share/locale/en_US.UTF-8/LC_MESSAGES/coreutils.mo", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/usr/share/locale/en_US.utf8/LC_MESSAGES/coreutils.mo", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/usr/share/locale/en_US/LC_MESSAGES/coreutils.mo", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/usr/share/locale/en.UTF-8/LC_MESSAGES/coreutils.mo", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/usr/share/locale/en.utf8/LC_MESSAGES/coreutils.mo", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/usr/share/locale/en/LC_MESSAGES/coreutils.mo", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/usr/share/locale-langpack/en_US.UTF-8/LC_MESSAGES/coreutils.mo", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/usr/share/locale-langpack/en_US.utf8/LC_MESSAGES/coreutils.mo", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/usr/share/locale-langpack/en_US/LC_MESSAGES/coreutils.mo", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/usr/share/locale-langpack/en.UTF-8/LC_MESSAGES/coreutils.mo", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/usr/share/locale-langpack/en.utf8/LC_MESSAGES/coreutils.mo", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/usr/share/locale-langpack/en/LC_MESSAGES/coreutils.mo", O_RDONLY) = -1 ENOENT (No such file or directory)
write(2, "rm: ", 4rm: )                     = 4
write(2, "cannot remove '.html'", 21cannot remove '.html')   = 21
open("/usr/share/locale/en_US.UTF-8/LC_MESSAGES/libc.mo", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/usr/share/locale/en_US.utf8/LC_MESSAGES/libc.mo", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/usr/share/locale/en_US/LC_MESSAGES/libc.mo", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/usr/share/locale/en.UTF-8/LC_MESSAGES/libc.mo", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/usr/share/locale/en.utf8/LC_MESSAGES/libc.mo", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/usr/share/locale/en/LC_MESSAGES/libc.mo", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/usr/share/locale-langpack/en_US.UTF-8/LC_MESSAGES/libc.mo", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/usr/share/locale-langpack/en_US.utf8/LC_MESSAGES/libc.mo", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/usr/share/locale-langpack/en_US/LC_MESSAGES/libc.mo", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/usr/share/locale-langpack/en.UTF-8/LC_MESSAGES/libc.mo", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/usr/share/locale-langpack/en.utf8/LC_MESSAGES/libc.mo", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/usr/share/locale-langpack/en/LC_MESSAGES/libc.mo", O_RDONLY) = -1 ENOENT (No such file or directory)
write(2, ": Permission denied", 19: Permission denied)     = 19
write(2, "\n", 1
)                       = 1
lseek(0, 0, SEEK_CUR)                   = -1 ESPIPE (Illegal seek)
close(0)                                = 0
close(1)                                = 0
close(2)                                = 0
exit_group(1)                           = ?
+++ exited with 1 +++

您必須在文件所在的分區上執行 fsck。

為此,您必須以單一模式啟動並執行類似的操作

fsck.ext4 /dev/yourpartdevice 

(或將 ext4 更改為分區類型 - 並用有問題的分區替換 yourpartdevice)

但是…“lsattr: Inappropriate ioctl for device While reading flags on .html”看起來是硬體問題,也許 fsck 將無法更正文件。

如果這解決了您的問題,請將其標記為正確答案。

更新閱讀此答案的其他使用者:考慮到 RAM 記憶體可以做很多瘋狂的事情,所以在執行 fsck 之前檢查你的 RAM 是好的,因為這會使 fsck 執行非常具有破壞性。

祝你好運!

引用自:https://unix.stackexchange.com/questions/464119