Yet another `rm: cannot remove 'file': Permission denied`

5,414

You must run fsck on the partition where the file is.

To do that you must boot in single mode and do something like

fsck.ext4 /dev/yourpartdevice 

(or change ext4 to the partition type - and replace yourpartdevice by the partition with problem)

But... "lsattr: Inappropriate ioctl for device While reading flags on .html" looks like to be a hardware problem, and maybe fsck will be not capable of correcting the file.

If this solve your problem please mark this as the correct answer.

UPDATE for other users reading this answer: Consider that RAM memory can do a lot of crazy things, so checking your RAM is good before running fsck, because that can make fsck to run very destructive.

Good Lucky!

Share:
5,414

Related videos on Youtube

Clay
Author by

Clay

Updated on September 18, 2022

Comments

  • Clay
    Clay over 1 year

    I want to remove the .html file from the /home/user1/html/ directory.

    I have tried nearly all of the solutions posted on a myriad of other web sites. Nothing is working.

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

    Properties of directory:

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

    Properties of file:

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

    Things I have tried on directory (all run successfully):

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

    Things I have tried on the file (all run successfully):

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

    I tried looking at the file's attributes (did not run successfully):

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

    strace with sudo:

    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 without sudo:

    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 +++
    
    • i336_
      i336_ over 5 years
      I was going to suggest chattr -i to make sure the immutable bit isn't set, but lsattr isn't working, so I would definitely run fsck -n to begin with.
    • Gerard H. Pille
      Gerard H. Pille over 5 years
      "user1@comp1:~/html$ ls -al" should have shown "." and ".." Did you leave them out. If so, can you add them to your question?
    • ilkkachu
      ilkkachu over 5 years
      What filesystem is that? What does df -T ~ or mount /home print? (or whatever the path is) Can you edit that information to the question?
    • Nateous
      Nateous over 5 years
      The -rwxrwxrwx 0 user1 user1 1365246 Aug 20 17:20 .html suggests the filesystem is corrupted, as the link count is zero, meaning the inode has no directory entries pointing to it... Except .html does. After a filesystem check, the file should appear in the lost+found directory, and the .html directory entry should be removed.
  • ilkkachu
    ilkkachu over 5 years
    lsattr is ext2/ext3/ext4-centric, so getting Inappropriate ioctl is perfectly normal if the filesystem isn't one of those.
  • i336_
    i336_ over 5 years
    DO NOT USE THE -y ARGUMENT THE FIRST TIME YOU RUN FSCK OR YOU MAY CORRUPT DATA. This being said, running fsck with -n - the opposite of -y, is exactly the right thing to do here.
  • doneal24
    doneal24 over 5 years
    @LucianoAndressMartini Not all Linux's use ext4 by default. For example, Red Hat 7 and it's variants use xfs by default.