I've got a file that I cannot remove via SSH.

If I run an ls command on the directory, it clearly exists, but if it try to run an rm on the file it says:

cannot remove 'database.sql': No such file or directory

If I check the permissions on both the file and folder, it is 777, so I should have access to delete it.

If I run lsattr, it tells me:

No such file or directory While reading flags on ./database.sql

Finally, if I try to run rm . it again tells me:

rm: cannot remove 'database.sql': No such file or directory

Somehow it both knows that file is there (many commands "see" it), and can't remove it.

all-in-one-wp-migration/storage/sgmq5lpwyiio>ls -l
total 2327360
-rwxrwxrwx 1 nobody nogroup 2383152307 Jun  3 05:56 database.sql

all-in-one-wp-migration/storage/sgmq5lpwyiio>rm database.sql
rm: cannot remove 'database.sql': No such file or directory

lsattr: No such file or directory While reading flags on ./database.sql

all-in-one-wp-migration/storage/sgmq5lpwyiio>rm *.*
rm: cannot remove 'database.sql': No such file or directory

  • 2
    Looks like filesystem corruption. What filesystem is it? What is the result of file * in that folder? Jun 4, 2020 at 22:39
  • It is a docker container, hosted on Azure. File * results in "database.sql: writable, executable, regular file, no read permission".
    – Ben
    Jun 4, 2020 at 22:53
  • The no read permission might point to the problem (if it's not corruption in whichever filesystem you are using). Jun 4, 2020 at 22:57
  • Can you run fsck on that volume? What filesystem is it? Jun 5, 2020 at 0:24
  • Running fsck returns: fsck from util-linux 2.29.2
    – Ben
    Jun 5, 2020 at 0:30

2 Answers 2


The reason could be that the file owner and group is set to "nobody" and "nogroup". The "nobody" user and "nogroup" user group have the least possible privileges on the system. But even then you should be able to delete the file.

Do you have write permission to the directory that the file is in? Deleting a file may require write permissions in the directory as well, since you are removing something from a directory. Did you try editing the file? The directory may not have write access for you but, the file may have write access.

It could be file or system corruption as stated in the comments above, or it could be that a service might be running and is using that file.

Try to do chown and chgrp to make you as the owner, and the owning group to a group that you are in.

  • Both commands fail on the file, and while they seem to run change nothing on the group level. My guess is that docker is overriding/undoing the change.
    – Ben
    Jun 5, 2020 at 14:34

I have run into similar problems when there is an unintended unnoticed space or tab character somewhere in the file name that is being printed during a listing done using some sort of wild-card character. In some shells, if you type a tab after the file name on a command line, it will fill in characters at the end that you might not be seeing. You might be able to check by using a character count with wc -c on the file name, being aware of the unprinted \n character that is always counted.

  • using wc -c database.sql just returns 0.
    – Ben
    Jun 5, 2020 at 14:38
  • "ls -1d database.sql* | wc -c" OR something like "ls -1d (ASTERISK)database.sql(ASTERISK) | wc -c " (whatever "ls" command prints only the name of the file of interest) I tried with * instead of (ASTERISK) and two of them disappear and turn the text between them into italics).
    – jmf7
    Jun 6, 2020 at 10:48
  • If filename is "visible.part " then: ls -1d *| egrep 'visible.part' | egrep '[ ]' should print the file (a space between the [ ]). To explicitly visualize the spaces: ls -1d * | egrep visible.part | egrep '[ ]' | sed -e's/^/=>/g' -e's/$/<=/g' which should print "=>visible.part <=' If there are spaces, you can delete by: "rm visible.part(backslash) (backslash) " if there were 2 spaces. (backslash is not printing out properly in the text box on this site, also the double space is printing out as a single space on this website)
    – jmf7
    Jun 6, 2020 at 19:23

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .