Linux deletes files or folders with special characters

Source: Internet
Author: User

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

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.