Delete a file with special characters [. \] in the file name

Source: Internet
Author: User

If the special character is '/', skip to the end of the question. If the special character is
One 'or a control character or a Chinese character. Please continue reading.

A typical solution is:

Rm-I some * pattern * that * matches * only * the * file * you * want

In this case, rm will confirm before deleting the files that meet your conditions, no
If your shell will change the eighth bit of each character to zero, it will be written in Chinese.
The file name may not be deleted!

And

Rm-ri.

In this way, rm will delete all files under the current directory, while deleting a file
You will be asked if you want to delete this file. Unfortunately, not every version of rm has
This can be used. In addition, even if it can be used, the current directory
You may need to use "chmod a-x" to find subdirectories.
It can avoid terrible consequences. Before "rm-r" or "rm" with ten-character characters, please go deep
Breathe and find out what you are doing!

And

Find.-type f...-OK rm '{}'\;

"..." Is a bunch of words used to identify the name of an archive. For example
After inode, use

Find.-num 12345-OK rm '{}'\;

Or

Find.-inum 12345-OK mv '{}' new-file-name \;

Delete or rename the name. The option "-OK" indicates that you are required to confirm before the find command is executed.
. If you are sure that the command is correct, or you are afraid that there are strange words in the file to be processed
If you use the "-exec" option to make the screen messy, you will not be asked to confirm it first.
.

What should I do when the file name contains?

This type of file is very special, and will only happen because of the kernel bug (
During NFS writing, the file names from remote machines are not specified.
Character filtering ). The first thing we need to do is to try to make a decision? Nbsp;
The problem may be so strange.

The UNIX directory is simply a pair of file names and inode numbers.
For example, a directory contains the following information:

Filename inode

File1 12345
File2.c 12349
File3 12347

Theoretically? The nbsp; '/' and '\ 0' characters cannot be used in the file name,
Because they have the following special purposes:

'/': Used to separate directory names and file names.
'\ 0': Specifies the ending character of the file name.

Very, extremely, and unfortunately, NFS developed by some vendors is responding to requirements of remote machines.
The name of a file containing a slash (/) will be created in an idiotic manner. For example, when someone is on a Mac
Or other non-Unix machines create a date-name file through NFS to your
In Unix. Then, your Unix directory may look like this:

Filename inode

91/02/07 12357

Neither the 'Find 'or 'rm' we mentioned earlier can delete this file, because
Other Unix programs forcibly interpret '/' as the preceding delimiter.

In fact, any common program will try to do unlink ("91/02/07 ").
For kernel, it indicates the file in the 02 subdirectory under unlink directory 91.
Case 07 ", but we do not have such an archive.
The files of "91/02/07" are in the current directory. This is a very subtle but important difference.

What should I do now? First, return to the Mac that generates such a messy file name.
Do you want to change NFS daemon to a file name. If not, you have
Ask your system manager for help. Please try one of the following methods:

1. Use "ls-I" to find the inode number of the file.
File system then clears the inode with "clri", and then
Pray for the success of "fsck. This method will delete this messy file name
File.

2. If you want to save the information of this file, try the following:

-Create a file under the parent directory of the directory where the file is located.
Sub-directories, which can be moved from the old directory to the new directory
.
-Use "ls-id" to obtain the inode number of the old directory
-Unmount the file system and clear it with "clri ".
Directory inode
-"Fsck": file system
-Mount the New file system
-Rename the new directory to the old directory name.
-Retrieve the file from lost + found, change the file name, and put it back to the original file.
.Copy codeThe Code is as follows:
The method created under cmd: md jb51 ..\
Delete method: rd jb51 ..\

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.