How to delete garbled or special character files in Linux

How to delete garbled or special character files in Linux

Due to encoding reasons, garbled characters will be generated when uploading or creating Chinese files or directories on a Linux server. If you want to delete it, you cannot delete it with the rm command. In this case, you can use the find command to delete the garbled files or directories.

In the Linux file system, each file has an i-node number, and the files can be managed by the i-node number. First enter the directory where the garbled file or directory is located

Use the ls -i command to find the inode of a file or directory.

The numeric string in front of the file or directory is the inode. Next, use the find command to query and delete this file or directory.

Note: This method only works for deleting files or empty folders.

How to delete a non-empty folder?

First, check the inode, and then use the following command:

find -inum 2236429 -exec rm -rf {} \;

It will prompt that the file or folder cannot be found, but it has actually been deleted.

How to delete files with garbled or special characters in the file name under Linux.

I encountered a problem today. A file name is “-MXV9.log ". When I delete it directly with rm, an error message is displayed.

[localhost]rm -MXV9.log
rm: illegal option -- M
rm: illegal option -- X
rm: illegal option -- V
rm: illegal option -- 9
rm: illegal option -- .
rm: illegal option -- l
rm: illegal option -- o
rm: illegal option -- g
Usage: rm [-Rfir] file ...

I started thinking about deleting with quotes, but found that deleting with quotes also reported an illegal option error.

I found some information and found that this kind of file can be deleted like this

First ls -i to find the file's inode, then delete it with the find command

[localhost]ls -ilrt

100985 -rw-r--r-- 1 tbcs users 0 Apr 18 11:32 -MXV9.log

The 100985 in the first column is the inode of the file. Execute the following command on the host to delete the file

[localhost]find ./ -inum 100985 -exec rm {} \;

This method is suitable for deleting files with garbled or special characters.

For example, if the file name is "*.txt" and you directly execute rm *.txt, all files ending with .txt in the folder will be deleted.

Summarize

The above is the full content of this article. I hope that the content of this article will have certain reference learning value for your study or work. Thank you for your support of 123WORDPRESS.COM. If you want to learn more about this, please check out the following links

You may also be interested in:
  • Detailed explanation of using top command to analyze Linux system performance
  • How to enhance Linux and Unix server security
  • Detailed explanation of the difference between chown and chmod commands in Linux
  • Use the more, less, and cat commands in Linux to view file contents
  • Explanation of Linux kernel optimization configuration for high-concurrency nginx server
  • How to modify the default encoding of mysql in Linux
  • Introduction to the use and disabling of transparent huge pages in Linux
  • Detailed explanation of upgrading Python and installing pip under Linux
  • How to use for loop combined with if to find files in Linux Shell directory
  • Linux system to view CPU, machine model, memory and other information

<<:  Navicat for MySQL scheduled database backup and data recovery details

>>:  Videojs+swiper realizes Taobao product details carousel

Recommend

A detailed introduction to Linux memory management and addressing

Table of contents 1. Concept Memory management mo...

react-beautiful-dnd implements component drag and drop function

Table of contents 1. Installation 2.APi 3. react-...

Key points for writing content of HTML web page META tags

The META tag is an auxiliary tag in the head area...

Several commonly used single-page application website sharing

CSS3Please Take a look at this website yourself, ...

Introducing multiple custom fonts in CSS3

Today I found a problem in HTML. There are many d...

mysql row column conversion sample code

1. Demand We have three tables. We need to classi...

Installation and configuration tutorial of MongoDB under Linux

MongoDB Installation Choose to install using Yum ...

Detailed example of clearing tablespace fragmentation in MySQL

Detailed example of clearing tablespace fragmenta...

The most comprehensive explanation of the locking mechanism in MySQL

Table of contents Preface Global Lock Full databa...

Use semantic tags to write your HTML compatible with IE6,7,8

HTML5 adds more semantic tags, such as header, fo...

Solution to the problem of large font size on iPhone devices in wap pages

If you don't want to use javascript control, t...

Implement QR code scanning function through Vue

hint This plug-in can only be accessed under the ...