Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use inode to delete a specified file in Linux

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

This article is about how to use inode to delete specified files in Linux, the editor thinks it is very practical, so I share it with you to learn. I hope you can get something after reading this article.

The object of operation is generally a file similar to the following:

[root@server tmp] # ll Total usage 61404KQ root@server tmp RFT-1 root root 0 June 16 14:58?-rw-r--r-- 1 root root 0 June 19 12:29?-rw-r--r-- 1 root root 0 June 21 14:53? 3kq Ulyr Mustang-1 root root June 21 14:53? 6 ? Xf??mA???9???T cargo-rw-r--r-- 1 root root 19 June 19 12:29 9 yearly syphilzDuring LittleThread I installed MOTHANG 8zymorph 9??U@?XlAI @] K

The reasons for this type of file are:

1. A network exception when uploading a file results in

Some file names created by 2.Windows are not properly recognized under Linux

3. Chinese special characters cannot be recognized

The solution is as follows:

1. Query the image values of these files

Ll-I

[root@server tmp] # ll-I Total dosage 6140415206100-rw-r--r-- 1 root root 0 16 14:58? 15206090-rw-r--r-- 1 root root 0 June 19 12:29-15206092-rw-r--r-- 1 root root 0 June 21 14:53? 3kqU15206233-rw-r--r-- 1 root root 0 June 21 14:53? 6 ? Xf??mA???9???T Xf??mA???9???T 15206235-rw-r--r-- 1 root root June 21 14:53.

Above, the leftmost number is the inode value of the corresponding file. However, you cannot delete the file directly by using the rm command. You need to use other commands together.

two。 Delete exception file

Under normal circumstances, these files are also unavailable, but commands related to rm should be carefully tested beforehand. It is not too much to be proficient in the operation. Without these garbled files, you can use normal files for testing.

There are several ways to do this:

Create the required files first

[root@zstest1 tmp] # cd / tmp [root@zstest1 tmp] # touch aaa bbb ccc ddd eee [root@zstest1 tmp] # ll-I Total dosage 01442581-rw-r--r-- 1 root root 0 September 22 15:00 aaa1442582-rw-r--r-- 1 root root 0 September 22 15:00 bbb1442583-rw-r--r-- 1 root root 0 15:00 ccc1442584-rw-r--r-- 1 root root 0 September 22 15:00 ddd1442585 -rw-r--r-- 1 root root 0 September 22 15:12 eee

(1) use the delete parameter that comes with find to delete aaa files.

[root@zstest1 tmp] # find. / *-inum 1442581-delete [root@zstest1 tmp] # ll-I Total dosage 0 1442582-rw-r--r-- 1 root root 0 September 22 15:00 bbb 1442583-rw-r--r-- 1 root root 0 September 22 15:00 ccc 1442584-rw-r--r-- 1 root root 0 September 22 15:00 ddd 1442585-rw-r--r-- 1 root root 0 September 22 15:12 eee

(2) use the-exec parameter that comes with find to delete the bbb file with the rm command (confirm deletion)

[root@zstest1 tmp] # find. / *-inum 1442582-exec rm-I {}\; rm: do you want to delete the ordinary empty file ". / bbb"? y [root@zstest1 tmp] # ll-I Total usage 0 1442583-rw-r--r-- 1 root root 0 September 22 15:00 ccc 1442584-rw-r--r-- 1 root root 0 September 22 15:00 ddd 1442585-rw-r--r-- 1 root root 0 September 22 15:12 eee

(3) use the-exec parameter that comes with find to delete the ccc file with the rm command (no deletion confirmation)

[root@zstest1 tmp] # find. / *-inum 1442583-exec rm-f {}\; [root@zstest1 tmp] # ll-I total dosage 0 1442584-rw-r--r-- 1 root root 0 September 22 15:00 ddd 1442585-rw-r--r-- 1 root root 0 September 22 15:12 eee

(4) use find and xargs to delete ddd files (the-I parameter cannot be used for deletion confirmation)

[root@zstest1 tmp] # find. / *-inum 1442584 | Total amount of xargs rm-f [root@zstest1 tmp] # ll-I 0 1442585-rw-r--r-- 1 root root 0 September 22 15:12 eee

(5) use the rm command to delete the specified file (the file name found by the find command)

[root@zstest1 tmp] # rm `find. / *-inum 1442574` rm: do you want to delete the ordinary empty file ". / eee"? y [root@zstest1 tmp] # ll Total usage 0 # use the-inum option of the find command to confirm the file name [root@zstest1 tmp] # touch fff [root@zstest1 tmp] # ll-I Total usage 01442574-rw-r--r-- 1 root root 0 September 22 15:38 fff [root@zstest1 tmp] # find. / *-inum 1442574. / fff above is how to delete a specified file using inode in Linux The editor believes that there are some knowledge points that we may see or use in our daily work. I hope you can learn more from this article. For more details, please follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report