CentOS7 based on the development of the road---daily use: Linux delete files with special characters __linux

Source: Internet
Author: User
Linux deletes files with special characters

Sometimes we need to delete some files with special characters, but we don't know how to delete them, like I do, and here are some of the ways I've learned to delete: rm–-filename rm./-filename RM * some* rm-i * through inode number to understand RM syntax

First understand the following RM syntax, in fact, I did not have a good understanding of ‵‵‵‵‵, in the terminal window to type Rm–help

[Root@localhost tmp]$ rm--help usage:rm [OPTION] ...
FILE ...

  Remove (unlink) the FILE (s). -F,--force ignore nonexistent files and arguments, never prompt-i prompt, before every REM  Oval-i prompt once before removing than more three files, or when removing recursively; Less intrusive than-i, while still giving protection against most mistakes--interactive[ =when] Prompt According to When:never, once (-i), or always (-i);
                          Without when the prompt always--one-file-system when removing a hierarchy recursively and skip any Directory This is on a file system different from this of the corresponding command line AR Gument--no-preserve-root do not treat '/' specially--preserve-root does not remove '/' (default)-R, R,
 --recursive Remove directories and their contents recursively -D,--dir remove empty directories-v,--verbose explain what are being done--help Displa  Y this Help and exit--version output version information and exit by default, RM does not remove directories.

Use the--recursive (-r or-r) option to remove each listed directory, too, along and all of its contents. To remove a file whose name starts with a '-', for example '-foo ', use one of these commands:rm---foo rm./-foo N OTE that if your use RM to remove a file, it might is possible to recover some of its contents, given sufficient  and/or time.

For greater assurance the contents are truly unrecoverable, consider using shred. GNU coreutils online Help:  
using the Rm–-filename command to remove 

RM directly deletes the file with the start of the filename, prompting for failure

[Root@localhost tmp]# rm-er.txt
rm:invalid Option--' e '
Try ' rm./-er.txt ' To remove the ' file '-er.txt '.
Try ' rm--help ' for the more information.

Use rm–-filename Delete, note that RM is followed by two-

[Root@localhost tmp]# RM---er.txt
rm:remove Regular empty file '-er.txt '? y
[root@localhost tmp]# ls
link
  [root@localhost tmp]#

You can see that-er.txt has been removed using the RM./-filename command

When you use the rm–-filename command to delete a file, you are prompted to try using RM./-er.txt to delete files

[Root@localhost tmp]# rm./-er.txt 
rm:remove Regular Empty file './-er.txt '? y
[root@localhost tmp]# ls
l Ink

You can see that-er.txt has been removed using the RM *some* command

Sometimes, some files with special characters are encountered, using Rm–-filename or using RM./-filename also deleted, you have to use the RM some command to delete, such as to delete? *&sni.txt this file
This command should be used with caution, * is a wildcard, you may delete the files with some characters

[Root@localhost tmp]# ll total
0
-rw-rw-r--. 1 root   0,  9 12:10-er.txt
-rw-rw-r--. 1 Root   root   0,  9 12:10-rr20170109122610.txt
-rw-rw-r--. 1 Chenzl Chenzl 0,  9 14:05?*& Sni.txt
[root@localhost tmp]# rm--? *&sni.txt
[2] 15211 rm:remove The regular empty
file '-er.txt '? Bash : Sni.txt:command not found

... [2]+  Stopped                 rm-i--? *
[Root@localhost tmp]# rm./?*&sni.txt
[3] 15218
rm:remove Regular empty file './-er.txt '? Bash:sni.txt:command not found

... [3]+  Stopped                 rm-i./?*
[root@localhost tmp]# RM *sni.txt Rm:remove The regular
file ' empty Sni.txt '? Y
[root@localhost tmp]# ll total
0
-rw-rw-r--. 1 root root 0,  9 12:10-er.txt
-rw-rw-r--. 1 ro OT root 0,  9 12:10-rr20170109122610.txt
[root@localhost tmp]#
Use the rm-i * command to delete

If you use the above methods still can't delete, you can try the ultimate big strokes, such as I want to delete? *&sni.txt this file, when the hint is want to delete the file, enter Y, otherwise enter n

[Root@localhost tmp]# ll total
0
-rw-rw-r--. 1 Chenzl Chenzl 0 before  9 14:14? *&sni.txt
-rw-r--r--. 1 ro OT   root   0  9 14:15 testfile
[root@localhost tmp]# rm-i * rm:remove regular empty
file '? *&sni . txt '?  Y
rm:remove regular empty file ' testfile ' n
[root@localhost tmp]# ll total
0
-rw-r--r--. 1 root 0  9 14:15 testfile
[root@localhost tmp]#
Delete by inode number

can also be deleted by the inode number of the file, first find the document inode number, using Ls-il can see, such as? *&sni.txt the inode number for this file is 74150596, and then the file is deleted with the Find command.

[root@localhost tmp]# Ls-il total
0
74150596-rw-rw-r--. 1 Chenzl Chenzl 0 before  9 14:27? *&sni.txt
671 32857-rw-r--r--. 1 root   0  9 14:15 testfile
[root@localhost tmp]# find.-inum 74150596-exec {} \;
Rm:remove regular empty file './?*&sni.txt '? Y

When the use of one of these methods does not work, the text of several methods are tried, if still not, I will not be able to ‵‵‵‵‵‵‵, but I believe the final big strokes can be done.

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.