How Linux uses inode to delete files

  
                  

The inode of a file defines the size of the file, the characteristics of the file for everyone, and so on. Each file and directory has its own unique inode number. But why use inode to delete files instead of using the usual rm -rf command? The reason is that if you accidentally create files and directories with special characters, such as filenames with ? * ^, it will be difficult to delete. Here we will introduce: 1) how to find the inode of files and directories; 2) delete the specific inode file with the find command; 3) other useful methods to delete stubborn files. * How to find the inode of a file?

Use stat or ls -il. The ls command with the -i parameter refers to the inode of the display file.

* How do I delete this file after finding the inode? Find . -inum [inode number] -exec rm -i {} /;

1) Let's complete the experiment and create a file with special characters:

$ cd /tmp $ Touch “/+Xy /+/8″ $ ls

2) Try to delete with rm command

$ rm /+Xy /+/8

3) Find The inode number of this file

$ ls -il 342137 -rw-r–r– 1 tw tw 0 2008-11-20 08:57 /+Xy /+/8

4 ) 342137 is the inode number we are looking for. Use the find command to delete it

$ find . -inum 342137 -exec rm -i {} /;

For example, your system has ”2008/11/20″ With rm it can't be deleted. Linux does not allow you to create this file, but it works on Windows. So the use of find with inode is here.

Here are some other useful tips for removing:

* You can try to delete files by quoting the file name. For example, “–help” files, you can use rm “–help”delete

* You can also delete files with unlink. Unlink. The unlink command calls the unlink function to delete a specific file.

* Use mtools to delete illegal files created under Windows. This method is most useful when the find command matches the inode failure. Specially deal with the folder created by the autorun.inf virus.

You can also use xargs with rm to delete files in different locations in batches: write the full path of the file to be deleted to a text file, such as file.txt as follows: file1 /tmp/file2.txt ~/data .txt

Then run the following command to delete the file listed in file.txt $ xargs rm

Copyright © Windows knowledge All Rights Reserved