Example of deleting a specified file method using inode under Linux
- 2020-06-19 12:29:07
- OfStack
preface
It is well known that in Linux, sometimes the file name is confused or some special Chinese files, in this case, it is difficult to delete the file name.
At the same time, any file in linux must have its own value of inode for 1, and then inode can be used to delete the file of the exception file name.
The operation object 1 is generally similar to the following file:
[root@server tmp]# ll
The total amount 61404-rw-r--r-- 1 root root 0 6 month 16 14:58 ?
-rw-r--r-- 1 root root 0 6 month 19 12:29 ??
-rw-r--r-- 1 root root 0 6 month 21 14:53 ???3kqU-rw-r--r-- 1 root root 0 6 month 21 14:53 ?6;?Xf??mA???9???T֙
-rw-r--r-- 1 root root 0 6 month 19 12:29 9y??????sy?z?D?l???I?MO???8z????@]9??U@?XlAI]?k
Reasons for producing such documents:
1. Network anomaly caused when uploading files
2. Some file names created by Windows are not recognized properly under Linux
3. Chinese special characters cannot be recognized
The solution is as follows:
1. Query the inode value of these files
ll -i
[root@server tmp]# ll -i
The total amount 6140415206100 -rw-r--r-- 1 root root 0 6 month 16 14:58 ?15206090 -rw-r--r-- 1 root root 0 6 month 19 12:29 ??15206092 -rw-r--r-- 1 root root 0 6 month 21 14:53 ???3kqU15206233 -rw-r--r-- 1 root root 0 6 month 21 14:53 ?6;?Xf??mA???9???T֙
15206235 -rw-r--r-- 1 root root 0 6 month 21 14:53 A??K?
Above, the leftmost number is the inode value of the corresponding file. However, rm command cannot be used to delete the file directly, and other commands are required
2. Delete the exception file
Under normal circumstances, these files are also not available, but the command involving rm should be careful, do 1 test in advance, it is not too much to be skilled operation, without these messy files, you can use normal files to do the test,
There are several ways:
First create the required files
[root@zstest1 tmp]# cd /tmp
[root@zstest1 tmp]# touch aaa bbb ccc ddd eee
[root@zstest1 tmp]# ll -i
The total amount 01442581 -rw-r--r-- 1 root root 0 9 month 22 15:00 aaa1442582 -rw-r--r-- 1 root root 0 9 month 22 15:00 bbb1442583 -rw-r--r-- 1 root root 0 9 month 22 15:00 ccc1442584 -rw-r--r-- 1 root root 0 9 month 22 15:00 ddd1442585 -rw-r--r-- 1 root root 0 9 month 22 15:12 eee
(1) aaa file is deleted by using delete parameter which comes with find
[root@zstest1 tmp]# find ./* -inum 1442581 -delete
[root@zstest1 tmp]# ll -i
The total amount 0
1442582 -rw-r--r-- 1 root root 0 9 month 22 15:00 bbb
1442583 -rw-r--r-- 1 root root 0 9 month 22 15:00 ccc
1442584 -rw-r--r-- 1 root root 0 9 month 22 15:00 ddd
1442585 -rw-r--r-- 1 root root 0 9 month 22 15:12 eee
(2) Use the -ES70en parameter with find and rm command to delete bbb file (for deletion confirmation)
[root@zstest1 tmp]# find ./* -inum 1442582 -exec rm -i {} \;
rm : Whether to delete a plain empty file "./bbb"?y
[root@zstest1 tmp]# ll -i
The total amount 0
1442583 -rw-r--r-- 1 root root 0 9 month 22 15:00 ccc
1442584 -rw-r--r-- 1 root root 0 9 month 22 15:00 ddd
1442585 -rw-r--r-- 1 root root 0 9 month 22 15:12 eee
(3) Use the -ES78en parameter with rm command to delete ccc file (do not delete confirmation)
[root@zstest1 tmp]# find ./* -inum 1442583 -exec rm -f {} \;
[root@zstest1 tmp]# ll -i
The total amount 0
1442584 -rw-r--r-- 1 root root 0 9 month 22 15:00 ddd
1442585 -rw-r--r-- 1 root root 0 9 month 22 15:12 eee
(4) Use find and xargs to delete ddd file (-ES88en parameter cannot be used for deletion confirmation)
[root@zstest1 tmp]# find ./* -inum 1442584 |xargs rm -f
[root@zstest1 tmp]# ll -i
The total amount 0
1442585 -rw-r--r-- 1 root root 0 9 month 22 15:12 eee
(5) Use rm command to delete the specified file (the file name found by find command)
[root@zstest1 tmp]# rm `find ./* -inum 1442574`
rm : Whether to delete a plain empty file "./eee"?y
[root@zstest1 tmp]# ll
The total amount 0
# use find Of the command -inum Option confirm filename
[root@zstest1 tmp]# touch fff
[root@zstest1 tmp]# ll -i
The total amount 01442574 -rw-r--r-- 1 root root 0 9 month 22 15:38 fff
[root@zstest1 tmp]# find ./* -inum 1442574
./fff
Conclusion 1:
The different deletion methods above are generally based on specifying the inode value of the file, using the -ES104en option of the find command to confirm its filename, and then passing it to the rm command to delete it
Over, hehe hehe
conclusion