1

1. List the inodes of all files in the directory

Operation command: ls -li .

 [niewj@niewj ~]$ ls -li .
总用量 392992
1328244 -rw-rw-r-- 1 niewj niewj       654 4月  27 22:42 -d
1328240 -rw-rw-r-- 1 niewj niewj         0 4月  27 22:42 -H
1322919 -rw-rw-r-- 1 niewj niewj  57276047 7月   6 2020 kafka_2.12-2.2.2.tgz
1328256 -rw-rw-r-- 1 niewj niewj 334034602 9月  14 2017 mysql-5.7.20-winx64.zip
1449101 drwxrwxr-x 2 niewj niewj     20480 9月   1 2020 sf_down
1328798 -rw-r--r-- 1 niewj niewj    227852 9月   1 2020 sf_down.zip
1329533 -rw-rw-r-- 1 niewj niewj  10849188 12月 28 2020 sublime.zip

The above is mainly -i option to indicate inode, or ls -i .

2. Delete documents based on inode number

For example, files such as "-d" and "-H" in the above directory are created under abnormal circumstances. It is inconvenient to delete them directly by name. You can delete them by specifying inode

2.1 Delete method 1-find front

Such as delete the "-d" file
find . -inum 1328244 -exec rm -i {} \;
If you don't need confirmation, just delete it (the "-H" file above):
find . -inum 1328240 -exec rm -if {} \;

2.1 Delete method 2-find post

 rm `find . -inum 1328244`

Similarly, since we can get the file name according to the find command, we can also perform other operations on it:

 # 查看文件类型
[niewj@niewj ~]$ file `find . -inum 1449101`
./sf_down: directory

# 列出文件详情
[niewj@niewj ~]$ ls -l  `find . -inum 1449101`
总用量 24
-rw-rw-r-- 1 niewj niewj 102 9月   1 2020 blankfile
-rw-rw-r-- 1 niewj niewj 352 9月   1 2020 comment.txt
-rw-rw-r-- 1 niewj niewj 278 9月   1 2020 moon.txt
-rw-rw-r-- 1 niewj niewj 213 9月   1 2020 test
-rw-r--r-- 1 niewj niewj 999 9月   1 2020 vim使用整理.md
-rw-rw-r-- 1 niewj niewj  97 9月   1 2020 zoo.cfg

3. Summary

// 1. Display inode
ls -li .
// 2. Delete the file found according to the inode
rm `find . -inum 12345`
find . -inum 12345 -exec rm -i {} \;


丰木
322 声望19 粉丝

遇见超乎想象的自己!