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

vue-cropper component realizes image cutting and uploading

This article shares the specific code of the vue-...

Web page image optimization tools and usage tips sharing

As a basic element of a web page, images are one ...

Summary of MySql index, lock, and transaction knowledge points

This article summarizes the knowledge points of M...

Detailed explanation of linux nslookup command usage

[Who is nslookup?] 】 The nslookup command is a ve...

Two ways to implement HTML to randomly drag content positions

Test: Chrome v80.0.3987.122 is normal There are t...

Use CSS content attr to achieve mouse hover prompt (tooltip) effect

Why do we achieve this effect? ​​In fact, this ef...

Google Translate Tool: Quickly implement multilingual websites

Google China has released a translation tool that ...

Grid systems in web design

Formation of the grid system In 1692, the newly c...

MySQL 8.0.15 installation and configuration graphic tutorial under Win10

This article records the installation and configu...

Will Update in a Mysql transaction lock the table?

Two cases: 1. With index 2. Without index Prerequ...

How to compile and install opencv under ubuntu

Easy installation of opencv2: conda install --cha...

Detailed explanation of filters and directives in Vue

Table of contents vue custom directive Global Dir...

Mac+IDEA+Tomcat configuration steps

Table of contents 1. Download 2. Installation and...