Linux remove garbled files and folders (support batch) method

  
                  

1. Query inode :
Code is as follows

[oracle@test]$ ll -i total 14694452 17956913 -rw-r–r– 1 oracle oinstall 0 Jan 18 20:24 1?.txt

2. Modify the test file name:
The code is as follows find . -inum 17956913 -exec mv {} file.txt ;

3. Delete the garbled file
The code is as follows [oracle@test]$ ll -i total 14694452 …. -rw-r–r– 1 oracle oinstall 0 Jan 18 20:24 file.txt

Record: delete garbled files can use find. -inum 17956913 -exec rm {} ;

Folder

For folders, especially non-empty folders, the above method is not applicable. You need to use another parameter to implement it. The first thing is to view the nodes of the garbled folder. No.
Code is as follows

ls -i 18612483 . block.?.. - Thank you, Love(128kbps) 2011.06.22

Next use the find command to delete the
code as follows

find -inum 18612483 -exec rm -rf {} ; find: ./瑗 block.?.. - Thank you, Love(128kbps) 2011.06.22: No such file or directory

We couldn't find this file or folder, but it has actually been deleted. The -exec function is to execute the command after the search, where {} represents the result of the previous query, the space +; is the terminator, and the others do not say. -exec can be followed by any common commands, so this method is not only applicable to folders, but also to files.

Tips

How to delete in batches? In fact, it's very simple, just use for
Code as follows

File

for n in 22413315 22413314;do find -inum $n -delete;done

Folder

for n in 22413315 22413314;do find -inum $n -exec rm -rf {} ;;done

$n is the name of the variable, which is consistent with the definition of for later, nothing else to say For other operations.

Copyright © Windows knowledge All Rights Reserved