Linux – File does NOT exist but ls shows “No such file or directory” error

bashlinuxls

File system ext4 //
which ls -> /bin/ls //
Bash -> 3.2.57(2)-release //
whoami -> admin

If I run ls then I firstly get a list of files with error

"No such file or directory"

and then the healthy files of the directory.

The folder that contains these bad files has an unusual size:

enter image description here
enter image description here

Concerning the files with error, I cannot:

  1. delete the file

  2. copy the file

  3. move the file

  4. delete the directory since it is not empty (rm -r [DirectoryName])

  5. Bad files are not shown/listed on either Mac OS nor MS-Windows

I can:

  1. Move the content of the directory (mv) including bad files

  2. Get tab to complete the name of the bad file

Any hint? Either to delete them or to recover them.

Best Answer

As per comment - the solution was to unmount and fsck the filesystem (using e2fsck or fsck.ext4).

It would seem that the filesystem got corrupted - possibly due to a sudden outage while writing to the disk - and the filesystem would have detected the problem and locked itself until repaired to prevent further damage to itself.

Related Question