Home  >  Article  >  Operation and Maintenance  >  How to delete garbled files under Linux

How to delete garbled files under Linux

巴扎黑
巴扎黑Original
2017-08-22 14:09:522917browse

Deleting files under Linux is a very troublesome thing when encountering special characters.

1. If the file name contains characters like '-' or '--'

The deletion method is: rm -- file name

For example, the file name is: -pythontab.tgz

If you use ordinary methods to delete:

rm -pythontab.tgz

The result is error:

rm: invalid option -- pythontab

Try `rm --help' for more information.

can be used:

rm -- -pythontab.tgz

will be deleted successfully.

2. Delete files containing other special characters

For file names containing other special characters, such as a8093152e673feb7aba1828c43532094!*, etc., you can use

"" to escape Symbol or "" double quotation marks to enclose the control

such as ">" or "*"

[root@test]# rm >
[root@test]# rm “*”

3. Delete the garbled file names that the system cannot print (ultimate solution)

There is a file in the system whose file name is all garbled, and there is no way to delete it (the system cannot print garbled symbols). At this time, we can use the inode number to delete it.

[root@test]# ll -i
total 14694452
17956913 -rw-r--r-- 1 test test 4096 Nov 24 16:24 1?.txt
[root@test]# find . -inum 17956913 -exec rm {} \;

After testing, the above method is definitely available

The above is the detailed content of How to delete garbled files under Linux. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn