Skip to main content

How to delete a file named "filen/ame" (with slash) on an ext4 filesystem in debugfs? [Resolved]

Playing with e2fsprogs debugfs, by change/accident, a file named filen/ame was created. Obviously the forward slash character / serves as the special separator character in pathnames.

Still using debugfs I wanted to remove the file named filen/ame, but I had little success, since the / character is not interpreted as part of the filename?

Does debugfs provide a way to remove this file containing the slash? If so how?

I used:

cd /tmp
echo "content" > contentfile
dd if=/dev/zero of=/tmp/ext4fs bs=1M count=50
mkfs.ext4 /tmp/ext4fs
debugfs -w -R "write /tmp/contentfile filen/ame" /tmp/ext4fs
debugfs -w -R "ls" /tmp/ext4fs

which outputs:

debugfs 1.43.4 (31-Jan-2017)
 2  (12) .    2  (12) ..    11  (20) lost+found    12  (980) filen/ame

I tried the following to remove the filen/ame file:

debugfs -w -R "rm filen/ame" /tmp/ext4fs

but this did not work and only produced:

debugfs 1.43.4 (31-Jan-2017)
rm: File not found by ext2_lookup while trying to resolve filename

Apart from changing the content of the directory node manually, is there a way to remove the file using debugfs ?

Asked March 20, 2017
Posted Under: Unix Linux
2 Answers

If you want a fix and are not just trying out debugfs, you can have fsck do the work for you. Mark the filesystem as dirty and run fsck -y to get the filename changed:

$ debugfs -w -R "dirty" /tmp/ext4fs
$ fsck -y /tmp/ext4fs
/tmp/ext4fs was not cleanly unmounted, check forced.
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Entry 'filen/ame' in / (2) has illegal characters in its name.
Fix? yes
$ debugfs -w -R "ls" /tmp/ext4fs
2  (12) .    2  (12) ..    11  (20) lost+found    12  (980) filen.ame   

Answered March 20, 2017

Congradulations on fsck working; if for some reason it didn't work the answer is ls -i1 followed by umount and then clri.


I have actually tested this method.

Answered March 20, 2017
@Random832: I had fsck not fix it of its own in ages past. :( – Joshua 1 hour ago
 CanDoerz  3 days ago
Your instructions require running fsck anyway - which will fix the problem, with the message Entry 'filen/ame' in / (2) has deleted/unused inode 12. Clear<y>? instead of the one noted in the other answer - but doing the clri is an extra step. There doesn't seem to be a way to resolve this purely from within debugfs. – Random832 1 hour ago
 CanDoerz  3 days ago
@hobbs: must make mine unusual then. Oh wait, nvm clri was just echo "clri $2" | debugfs "$1" – Joshua 1 hour ago
 CanDoerz  3 days ago
If this is Linux (which it seems like), it's worth noting that clri isn't a separate command (as it is on some other Unix systems), it's a subcommand inside debugfs. – hobbs 1 hour ago
 CanDoerz  3 days ago
Your Answer