[root@VM_168_102_centos tmp]# cp test_1.sh wanghan/
[root@VM_168_102_centos tmp]# ls wanghan
ap_1014.pid ceshi test test.sh test_1.sh
[root@VM_168_102_centos tmp]#
复制多个文件
说明:如果目标存在且是一个文件,复制无法进行
[root@VM_168_102_centos tmp]# ls wanghan
ap_1014.pid ceshi test test.sh test_1.sh
[root@VM_168_102_centos tmp]# cp test.sh test_1.sh wanghan/test.sh
cp: target `wanghan/test.sh' is not a directory
[root@VM_168_102_centos tmp]# cp test_1.sh test.sh lianxi
cp: target `lianxi' is not a directory
[root@VM_168_102_centos tmp]#
复制单独目录
说明:如果目标存在且是一个文件,复制无法进行
[root@VM_168_102_centos tmp]# cp -r test wanghan/test.sh
cp: cannot overwrite non-directory `wanghan/test.sh' with directory `test'
说明:如果目标不存在,创建新目录
[root@VM_168_102_centos tmp]# ls wanghan
ap_1014.pid ceshi test test.sh test_1.sh
[root@VM_168_102_centos tmp]# cp -r test wanghan/openstack
[root@VM_168_102_centos tmp]# ls wanghan
ap_1014.pid ceshi openstack test test.sh test_1.sh
[root@VM_168_102_centos tmp]# ls wanghan/openstack/
说明:如果目标存在且是一个目录,复制源目录至目标目录中且保持原名
[root@VM_168_102_centos tmp]# cp -r test wanghan/openstack
[root@VM_168_102_centos tmp]# ls wanghan/openstack
test
[root@VM_168_102_centos tmp]#
cp -r:递归处理,将指定目录下的文件与子目录一并处理
[root@VM_168_102_centos tmp]# cp -r test wanghan/openstack
[root@VM_168_102_centos tmp]# ls wanghan/openstack
test
[root@VM_168_102_centos tmp]#
cp –d:当源为链接文件时,复制链接文件本身而非指向的源文件
[root@VM_168_102_centos etc]# cp /etc/rc /tmp
[root@VM_168_102_centos etc]# ls -l /tmp
total 48
-rwxr-xr-x 1 root wanghan 2617 Aug 12 09:14 rc
[root@VM_168_102_centos etc]# rm -rf /tmp/rc
[root@VM_168_102_centos etc]# cp -d /etc/rc /tmp/
[root@VM_168_102_centos etc]# ls -l /tmp
total 44
lrwxrwxrwx 1 root wanghan 7 Aug 12 09:15 rc -> rc.d/rc
[root@VM_168_102_centos etc]#
cp –l:对源文件建立硬链接,而非复制文件
[root@VM_168_102_centos ~]# ls
0812080808 2014-05-16 ceshi test test.log wanghan
[root@VM_168_102_centos ~]# cat test.log
sdswwwd
[root@VM_168_102_centos ~]# cp -l test.log abc.log
[root@VM_168_102_centos ~]# ls -l
total 24
-rw-r--r-- 1 root wanghan 0 Aug 11 14:50 0812080808
drwxr-xr-x 2 root root 4096 Aug 12 09:20 2014-05-16
-rw-r--r-- 2 wanghan wanghan 8 Aug 11 15:30 abc.log
drwxr-xr-x 2 root wanghan 4096 Aug 11 15:55 ceshi
drwxr-xr-x 2 root wanghan 4096 Aug 11 15:46 test
-rw-r--r-- 2 wanghan wanghan 8 Aug 11 15:30 test.log
drwxr-xr-x 4 root wanghan 4096 Aug 11 15:56 wanghan
[root@VM_168_102_centos ~]# cat abc.log
sdswwwd
cp -s:对源文件建立符号链接,而非复制文件
[root@VM_168_102_centos ~]# cp -s test.log ceshi.log
[root@VM_168_102_centos ~]# ls -l
total 24
-rw-r--r-- 1 root wanghan 0 Aug 11 14:50 0812080808
drwxr-xr-x 2 root root 4096 Aug 12 09:20 2014-05-16
-rw-r--r-- 2 wanghan wanghan 8 Aug 11 15:30 abc.log
drwxr-xr-x 2 root wanghan 4096 Aug 11 15:55 ceshi
lrwxrwxrwx 1 root wanghan 8 Aug 12 09:30 ceshi.log -> test.log
drwxr-xr-x 2 root wanghan 4096 Aug 11 15:46 test
-rw-r--r-- 2 wanghan wanghan 8 Aug 11 15:30 test.log
drwxr-xr-x 4 root wanghan 4096 Aug 11 15:56 wanghan
[root@VM_168_102_centos ~]#
#mv命令:用来移动文件或者将文件改名 文件改名:
[root@VM_168_102_centos ~]# ls
0812080808 2014-05-16 abc.log ceshi ceshi.log test test.log wanghan
[root@VM_168_102_centos ~]# mv ceshi ceshi_1
[root@VM_168_102_centos ~]# ls
0812080808 2014-05-16 abc.log ceshi.log ceshi_1 test test.log wanghan
[root@VM_168_102_centos ~]#
mv -b:若覆盖文件,则先备份目标文件
[root@VM_168_102_centos ~]# mv abc.log -b wanghan/test.log
mv: overwrite `wanghan/test.log'? y
[root@VM_168_102_centos ~]# ls wanghan
ceshi test test.log test.log~
[root@VM_168_102_centos ~]# ls
0812080808 2014-05-16 ceshi.log ceshi_1 test wanghan
[root@VM_168_102_centos ~]# rm ceshi.log
rm: remove symbolic link `ceshi.log'? y
[root@VM_168_102_centos ~]# ls
0812080808 2014-05-16 ceshi_1 test wanghan
rm –f 不询问直接删除,强制性无提示
[root@VM_168_102_centos ~]# ls
0812080808 2014-05-16 abc.log ceshi_1 test wanghan
[root@VM_168_102_centos ~]# rm -f abc.log
[root@VM_168_102_centos ~]# ls
0812080808 2014-05-16 ceshi_1 test wanghan
rm –r 递归删除非空目录
[root@VM_168_102_centos ~]# ls wanghan
ceshi test test.log test.log~
[root@VM_168_102_centos ~]# rm -r wanghan
rm: descend into directory `wanghan'? y
rm: remove regular file `wanghan/test.log'? y
rm: remove directory `wanghan/ceshi'? y
rm: remove directory `wanghan/test'? y
rm: remove regular file `wanghan/test.log~'? y
rm: remove directory `wanghan'? y
[root@VM_168_102_centos ~]# ls
0812080808 2014-05-16 ceshi_1 test