zhyiwww
用平实的笔,记录编程路上的点点滴滴………
posts - 536,comments - 394,trackbacks - 0

场景:
做一个项目模板,如下:
test@andy-N61Vn:/tmp/xxx$ ll proj_template/
total 28
drwxrwxr-x 5 test test 4096 2012-07-10 11:46 ./
drwxrwxr-x 3 test test 4096 2012-07-10 11:46 ../
-rw-rw-r-- 1 test test  842 2012-07-10 11:46 .classpath
-rw-rw-r-- 1 test test 1052 2012-07-10 11:46 .project
drwxrwxr-x 2 test test 4096 2012-07-10 11:46 .settings/
drwxrwxr-x 3 test test 4096 2012-07-10 11:46 src/
drwxrwxr-x 5 test test 4096 2012-07-10 11:46 WebRoot/
新建项目:
从项目模板复制,用以下命令:
test@andy-N61Vn:/tmp/xxx$ cp proj_template/ demo -rf

就可以从模板项目创建一个新的项目。
项目文件如下:
test@andy-N61Vn:/tmp/xxx$ ll demo/
total 28
drwxrwxr-x 5 test test 4096 2012-07-10 11:48 ./
drwxrwxr-x 4 test test 4096 2012-07-10 11:48 ../
-rw-rw-r-- 1 test test  842 2012-07-10 11:48 .classpath
-rw-rw-r-- 1 test test 1052 2012-07-10 11:48 .project
drwxrwxr-x 2 test test 4096 2012-07-10 11:48 .settings/
drwxrwxr-x 3 test test 4096 2012-07-10 11:48 src/
drwxrwxr-x 5 test test 4096 2012-07-10 11:48 WebRoot/
假如:
我已经有了一个目录,如proj2,里面没有文件,如下:
test@andy-N61Vn:/tmp/xxx$ ll proj2
total 8
drwxrwxr-x 2 test test 4096 2012-07-10 11:50 ./
drwxrwxr-x 5 test test 4096 2012-07-10 11:50 ../
再做文件复制:
test@andy-N61Vn:/tmp/xxx$ cp proj_template/* proj2/ -rf
test@andy-N61Vn:/tmp/xxx$ ll proj2/
total 16
drwxrwxr-x 4 test test 4096 2012-07-10 11:51 ./
drwxrwxr-x 5 test test 4096 2012-07-10 11:50 ../
drwxrwxr-x 3 test test 4096 2012-07-10 11:51 src/
drwxrwxr-x 5 test test 4096 2012-07-10 11:51 WebRoot/
我们可以发现,在模板项目中存在的隐藏文件.project .classes .
.settings/并没有复制过来。

解决办法:
使用如下命令:
test@andy-N61Vn:/tmp/xxx$ cp proj_template/.  proj2 -rf
test@andy-N61Vn:/tmp/xxx$ ll proj2/
total 28
drwxrwxr-x 5 test test 4096 2012-07-10 11:52 ./
drwxrwxr-x 5 test test 4096 2012-07-10 11:50 ../
-rw-rw-r-- 1 test test  842 2012-07-10 11:52 .classpath
-rw-rw-r-- 1 test test 1052 2012-07-10 11:52 .project
drwxrwxr-x 2 test test 4096 2012-07-10 11:52 .settings/
drwxrwxr-x 3 test test 4096 2012-07-10 11:51 src/
drwxrwxr-x 5 test test 4096 2012-07-10 11:51 WebRoot/

上面的命令可以实现连同隐藏文件一同复制。
注意:
命令的关键地方,也就是红色字体的地方。





|----------------------------------------------------------------------------------------|
                           版权声明  版权所有 @zhyiwww
            引用请注明来源 http://www.blogjava.net/zhyiwww   
|----------------------------------------------------------------------------------------|
posted on 2012-07-10 11:52 zhyiwww 阅读(3484) 评论(1)  编辑  收藏

FeedBack:
# re: 用cp命令复制隐藏文件
2013-06-05 12:20 | 啊啊啊
当用cp的时候 想要复制隐藏的文件一起走
不要 cp -r ./templates/* ./templates.new

直接 cp -r templates/ templates.new

使用后面的方法就可以复制隐藏文件或者文件夹一起走了   回复  更多评论
  

只有注册用户登录后才能发表评论。


网站导航: