标签:特殊字符
linux系统支持用户创建包含连字符(-)的文件或文件夹,一个错误的操作有时可能会产生以下文件或文件夹:
[root@huntdb aa]# touch /tmp/aa/{,-,\\}-{0,1,2,3,4,5}
[root@huntdb aa]# ls
-0 --0 \-0 -1 --1 \-1 -2 --2 \-2 -3 --3 \-3 -4 --4 \-4 -5 --5 \-5
[root@huntdb aa]# ll
total 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 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我们试着用普通的rm删除时会提示:
[root@huntdb aa]# rm -f --0 rm: unrecognized option `--0‘ Try `rm --help‘ for more information.
查看rm man手册有如下描述:
To remove a file whose name starts with a ‘-’, for example ‘-foo’, use one of these commands: rm -- -foo rm ./-foo
使用这个办法删除带\的文件进应注意进行二次转义,否则无法删除。
[root@huntdb aa]# rm -f -- \-5 [root@huntdb aa]# ls -0 --0 \-0 -1 --1 \-1 -2 --2 \-2 -3 --3 \-3 -4 --4 \-4 --5 \-5 [root@huntdb aa]# rm -f ./\-5 [root@huntdb aa]# ls -0 --0 \-0 -1 --1 \-1 -2 --2 \-2 -3 --3 \-3 -4 --4 \-4 --5 \-5
正确的做法如下:
[root@huntdb aa]# rm -f -- \\-5 [root@huntdb aa]# ls -0 --0 \-0 -1 --1 \-1 -2 --2 \-2 -3 --3 \-3 -4 --4 \-4 --5 [root@huntdb aa]# rm -f ./\\-4 [root@huntdb aa]# ls -0 --0 \-0 -1 --1 \-1 -2 --2 \-2 -3 --3 \-3 -4 --4 --5
文件夹的删除与此相同。
还可以通过inode号进行删除:
[root@huntdb aa]# ls -li | grep -- -2
2752777 -rw-r--r-- 1 root root 0 Apr 2 22:52 -2
2752783 -rw-r--r-- 1 root root 0 Apr 2 22:52 --2
[root@huntdb aa]# find . -inum 2752783 -exec rm {} \;
[root@huntdb aa]# ls -li | grep -- -2
2752777 -rw-r--r-- 1 root root 0 Apr 2 22:52 -2本文出自 “HUNT” 博客,请务必保留此出处http://hunt1574.blog.51cto.com/1390776/1629585
标签:特殊字符
原文地址:http://hunt1574.blog.51cto.com/1390776/1629585