Actions

 Language:
 RSS flow:


Deleting files with weird characters


Introduction

Sometimes a directory contains some files whose names contains special characters that you cannot remove easily via the rm command.

Example:

  • ?
  • ?.
  • ?.gz
  • etc, etc...

Deleting those files

To delete those files, we will use an option of the ls command, which allows to find the inode number of files that we want to delete.
For simplicity, inodes are data structures containing information about files stored in the system. Each file has an inode number in the file system in which it resides.

Determination of inode numbers corresponding to these files

Launch:
ls -i
The command will return the list of all files, with their the corresponding inode number:
 957697 ?.
 957698 ?..gz
To delete the first file in the list, we have to delete the file that has the inode number 957697.

Deleting file via find command

Now that we have found the inode number, just ask the find command to delete it. To do this, enter:
find . -inum 957697 -exec rm -i {} \;
The command asks a confirmation to delete the file. You just have to confirm.

 

Go back