Use inode to delete files or directories

When there is a directory or file name in the linux file system with irregular characters, we can delete the secondary file or directory through the inode number of the file

For understanding of inode, please refer to Understanding inode

 

Delete Files

Get the inode number of the file to be deleted

For example, we want to delete a file with irregular characters in the /root/ directory

First enter the /root directory

cd /root

Since the name of this file cannot be written directly, the inodes of all files in the root directory are listed

ls -i

The number in front of the file to be deleted is the inode of the file. For example, if we delete the /root/nohup.out file, record the inode number of the file as 100823907

Delete the file corresponding to the inode through the obtained inode

Execute the following command in the /root (the directory where the file to be deleted is located), and then enter y to confirm the deletion. When you check again, the nohup.out file with the inode number of 100823907 has been deleted.

find . -inum 100823907 -exec rm -i {} \;

Delete file animation through inode

Delete directory

Get the inode number of the directory to be deleted

For example, we want to delete a directory with irregular characters in the /root/ directory

First enter the /root directory

cd /root

Since the name of this file cannot be written directly, all files in the root directory and the inode of the directory are listed

ls -i

The number in front of the directory to be deleted is the inode of the file. For example, if we delete the /root/out directory, the inode number of the file is recorded as 39066994

Delete the directory corresponding to the inode through the obtained inode

Execute the following command in the /root (the directory where the directory to be deleted is located). Although the file does not exist, the out directory with the inode number of 39066994 has been deleted when viewed again (ls -i /root).

find . -inum 39066994 -exec rm -r {} \;

Delete directory animation through inode

Guess you like

Origin blog.csdn.net/VoiceRoom/article/details/107685134