The Linux system enables users to create files or folders that contain hyphens (-), and an incorrect operation may sometimes result in the following files or folders:
[[email protected] aa]# touch /tmp/aa/{,-, \\}-{0,1,2,3,4,5}[[email protected] aa ]# ls-0 --0 \-0 -1 --1 \-1 -2 --2 \-2 -3 --3 \-3 -4 --4 \ -4 -5 --5 \-5[[email protected] aa]# lltotal 0-rw-r--r-- 1 root root 0 Apr 2 22:52 -0-rw-r--r-- 1 root Root 0 apr 2 22:52 --0-rw-r--r-- 1 root root 0 apr 2 22:52 \-0-rw-r--r-- 1 root root 0 apr 2 22:52 -1-rw-r--r-- 1 root root 0 Apr 2 22:52 --1-rw-r--r-- 1 root root 0 apr 2 22:52 \-1-rw-r--r-- 1 root root 0 apr &nBsp;2 22:52 -2-rw-r--r-- 1 root root 0 apr 2 22:52 --2 -rw-r--r-- 1 root root 0 apr 2 22:52 \-2-rw-r--r-- 1 Root root 0 apr 2 22:52 -3-rw-r--r-- 1 root root 0 apr 2 22:52 --3-rw-r--r-- 1 root root 0 apr 2 22:52 \-3-rw-r--r-- 1 root root 0 apr 2 22:52 -4- rw-r--r-- 1 root root 0 apr 2 22:52 --4-rw-r--r-- 1 Root root 0 apr 2 22:52 \-4-rw-r--r-- 1 root root 0 apr 2 22:52 -5-rw-r--r-- 1 root root 0 apr 2 22:52 --5-rw-r--r-- 1 root root 0 apr 2 22:52 \-5
When we try to delete with normal RM, we will prompt:
[[email protected] aa]# rm-f--0rm:unrecognized option '--0 ' Try ' rm--help ' for more information.
View the RM man manual with the following description:
To remove a file whose name starts with a '-', for example '-foo ', use one of these commands:rm---foo RM./-foo
Use this method to delete the file with \ \ should be aware of two escapes, otherwise it cannot be deleted.
[Roo[email protected] aa]# rm-f--\-5[[email protected] aa]# ls-0--0 \-0-1--1 \-1-2--2 \-2-3--3 \-3- 4--4 \-4--5 \-5[[email protected] aa]# rm-f./\-5[[email protected] aa]# ls-0--0 \-0-1--1 \-1-2--2 \-2 -3--3 \-3-4--4 \-4--5 \-5
The correct approach is as follows:
[[email protected] aa]# rm-f--\\-5[[email protected] aa]# ls-0--0 \-0-1--1 \-1-2--2 \-2-3--3 \-3-4 --4 \-4--5[[email protected] aa]# rm-f./\\-4[[email protected] aa]# ls-0--0 \-0-1--1 \-1-2--2 \-2-3 --3 \-3-4--4--5
The deletion of the folder is the same as this.
You can also delete by using the Inode number:
[Email protected] aa]# Ls-li | grep---22752777-rw-r--r--1 root root 0 Apr 2 22:52-22752783-rw-r--r--1 root root 0 Apr 2 22:52--2[[email Protect Ed] aa]# find. -inum 2752783-exec rm {} \; [Email protected] aa]# Ls-li | grep---22752777-rw-r--r--1 root root 0 Apr 2 22:52-2
This article is from the "HUNT" blog, make sure to keep this source http://hunt1574.blog.51cto.com/1390776/1629585
Linux deletes files or folders with special characters