Dec 14

[原]关于cp命令中拷贝所有的写法 多云

linuxing , 10:24 , 基础知识 » 系统命令 , 评论(3) , 引用(0) , 阅读(58281) , Via 本站原创 | |

其实这样的问题,不单cp命令有这样的问题,在所有涉及含有特殊字符意义文件的命令时,都需要考虑,例如rm:
引用
[root@dc5 new]# ll -a
total 12
drwxr-xr-x  3 root root 4096 Dec 15 12:14 .
drwxr-xr-x  4 root root 4096 Dec 15 11:55 ..
-rw-r--r--  1 root root    0 Dec 15 12:07 .test3
-rw-r--r--  1 root root    0 Dec 15 12:05 test1
drwxr-xr-x  2 root root 4096 Dec 15 12:14 test2
[root@dc5 new]# rm -rf *
[root@dc5 new]# ll -a
total 8
drwxr-xr-x  2 root root 4096 Dec 15 12:40 .
drwxr-xr-x  4 root root 4096 Dec 15 11:55 ..
-rw-r--r--  1 root root    0 Dec 15 12:07 .test3

正确的写法应该是:
引用
[root@dc5 new]# rm -rf .* *
rm: cannot remove `.' or `..'
rm: cannot remove `.' or `..'
[root@dc5 new]# ll -a
total 8
drwxr-xr-x  2 root root 4096 Dec 15 12:42 .
drwxr-xr-x  4 root root 4096 Dec 15 11:55 ..

当然,这是一样的:
引用
[root@dc5 new]# rm -rf * .[^.]*
[root@dc5 new]# ll -a
total 8
drwxr-xr-x  2 root root 4096 Dec 15 12:44 .
drwxr-xr-x  4 root root 4096 Dec 15 11:55 ..

※很多时候,预计的和实际的结果是完全不一样的。bash编写脚本尤其需要注意。
内文分页: [1] [2]
Tags: ,
秋忆
2013/06/16 13:24
有帮助。谢谢!
不错
2009/04/16 00:09
有帮助,谢谢楼主的总结和分享
chemmie
2007/11/28 15:46
zan
分页: 1/1 第一页 1 最后页
发表评论
表情
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
打开HTML
打开UBB
打开表情
隐藏
记住我
昵称   密码   游客无需密码
网址   电邮   [注册]