[ligang@centos6 test]$ ll total 4 -rw-r--r-- 1 ligang trainning 0 Mar 10 00:35 haha.txt drwxr-xr-x 2 ligang trainning 4096 Mar 10 00:19 test1 [ligang@centos6 test]$ cp haha.txt test1/ [ligang@centos6 test]$ ll test1/ total 4 -rw-r--r-- 1 ligang trainning 0 Mar 10 00:36 haha.txt -rw-r--r-- 1 ligang trainning 7 Mar 10 00:07 log1.txt -rw-r--r-- 1 ligang trainning 0 Mar 10 00:10 log2.txt [ligang@centos6 test]$ cp haha.txt test1/ [ligang@centos6 test]$ ll test1/ total 4 -rw-r--r-- 1 ligang trainning 0 Mar 10 00:36 haha.txt -rw-r--r-- 1 ligang trainning 7 Mar 10 00:07 log1.txt -rw-r--r-- 1 ligang trainning 0 Mar 10 00:10 log2.txt
(2)cp不能直接把文件夹复制给另外一个文件夹,否者要加参数-rf。如果要把一个文件夹下内容复制给另外一个文件夹则用dir/*
[ligang@centos6 test]$ cp test2/ test1 cp: omitting directory `test2/' [ligang@centos6 test]$ cp -rf test2/ test1 [ligang@centos6 test]$ ll total 12 -rw-r--r-- 1 ligang trainning 5 Mar 10 00:37 haha.txt drwxr-xr-x 3 ligang trainning 4096 Mar 10 00:42 test1 drwxr-xr-x 2 ligang trainning 4096 Mar 10 00:40 test2 [ligang@centos6 test]$ mkdir test3 [ligang@centos6 test]$ cp -af test3 test1 [ligang@centos6 test]$ ll test1 total 16 -rw-r--r-- 1 ligang trainning 5 Mar 10 00:37 haha.txt -rw-r--r-- 1 ligang trainning 7 Mar 10 00:07 log1.txt -rw-r--r-- 1 ligang trainning 0 Mar 10 00:10 log2.txt drwxr-xr-x 2 ligang trainning 4096 Mar 10 00:42 test2 drwxr-xr-x 2 ligang trainning 4096 Mar 10 00:42 test3 [ligang@centos6 test]$ mkdir test4 [ligang@centos6 test]$ c test4 -bash: c: command not found [ligang@centos6 test]$ cd test4 [ligang@centos6 test4]$ touch test.txt [ligang@centos6 test4]$ cd .. [ligang@centos6 test]$ cp -rf test4/ test1 [ligang@centos6 test]$ ll test1 total 20 -rw-r--r-- 1 ligang trainning 5 Mar 10 00:37 haha.txt -rw-r--r-- 1 ligang trainning 7 Mar 10 00:07 log1.txt -rw-r--r-- 1 ligang trainning 0 Mar 10 00:10 log2.txt drwxr-xr-x 2 ligang trainning 4096 Mar 10 00:42 test2 drwxr-xr-x 2 ligang trainning 4096 Mar 10 00:42 test3 drwxr-xr-x 2 ligang trainning 4096 Mar 10 00:45 test4 [ligang@centos6 test]$ cp test4/* test1 [ligang@centos6 test]$ ll test1 total 20 -rw-r--r-- 1 ligang trainning 5 Mar 10 00:37 haha.txt -rw-r--r-- 1 ligang trainning 7 Mar 10 00:07 log1.txt -rw-r--r-- 1 ligang trainning 0 Mar 10 00:10 log2.txt drwxr-xr-x 2 ligang trainning 4096 Mar 10 00:42 test2 drwxr-xr-x 2 ligang trainning 4096 Mar 10 00:42 test3 drwxr-xr-x 2 ligang trainning 4096 Mar 10 00:45 test4 -rw-r--r-- 1 ligang trainning 0 Mar 10 00:45 test.txt
9linux命令,touch
功能:用来修改文件时间戳linux命令,或者新建一个不存在的文件。
-r把指定文档或目录的日期时间,统统设成和参考文档或目录的日期时间相同。
-t使用指定的日期时间,而非现在的时间。格式: [[CC]YY]MMDDhhmm[.SS]
上一个教程:Linux中find命令的使用详解(上)
下一个教程:linux的zip命令详解