6)cp:复制文件或目录
注意:某个文件或目录被复制后,原始文件或目录依然存在。
cp 源文件(目录) 目标文件(目录)
-i:提示。
-r/-R参数:当【复制目录】的时候,必须用到这个参数。
-r/-R:递归复制目录。
-f参数:在搭建集群时,修改时区的时候用到
-f:覆盖已存在的目标文件,而不给出提示。
① 同一文件,复制到同一目录下,需要改名;否则,会报错。
[root@image_boundary Desktop]# ll total 8 drwxr-xr-x. 2 root root 4096 Oct 15 21:00 aa drwxr-xr-x. 3 root root 4096 Oct 15 21:00 bb [root@image_boundary Desktop]# cd aa [root@image_boundary aa]# ll total 4 -rw-r--r--. 1 root root 21 Oct 15 21:00 sum.txt -rw-r--r--. 1 root root 0 Oct 15 20:59 sum.txt~ "把当前目录下的sum.txt文件,复制到当前目录下。" "假如不修改文件名,会报错。" [root@image_boundary aa]# cp sum.txt sum.txt cp: `sum.txt' and `sum.txt' are the same file "修改文件名后,才不会报错。" [root@image_boundary aa]# cp sum.txt sum1.txt [root@image_boundary aa]# ll total 8 -rw-r--r--. 1 root root 21 Oct 15 21:04 sum1.txt -rw-r--r--. 1 root root 21 Oct 15 21:00 sum.txt -rw-r--r--. 1 root root 0 Oct 15 20:59 sum.txt~
② 同一文件,复制到不同目录下,不需要改名;
[root@image_boundary Desktop]# ll total 8 drwxr-xr-x. 2 root root 4096 Oct 15 21:04 aa drwxr-xr-x. 3 root root 4096 Oct 15 21:00 bb "将aa目录下的sum.txt文件,复制到bb目录下,不需要修改名称。" [root@image_boundary Desktop]# cp aa/sum.txt bb/ [root@image_boundary Desktop]# cd bb [root@image_boundary bb]# ll total 8 drwxr-xr-x. 2 root root 4096 Oct 15 21:01 bbb -rw-r--r--. 1 root root 21 Oct 15 21:07 sum.txt
③ 递归复制bb目录中的东西(既包括文件,也包括目录),到aa目录中去。
"由于复制目录,因此必须使用参数【-r/-R】" [root@image_boundary Desktop]# ll total 8 drwxr-xr-x. 2 root root 4096 Oct 15 21:52 aa drwxr-xr-x. 3 root root 4096 Oct 15 21:07 bb "将bb目录复制到aa目录下。" "注意:复制目录的时候,必须要使用参数-r或者-R" [root@image_boundary Desktop]# cp -r bb aa/ [root@image_boundary Desktop]# cd aa [root@image_boundary aa]# ll total 4 drwxr-xr-x. 3 root root 4096 Oct 15 21:53 bb -rw-r--r--. 1 root root 0 Oct 15 20:59 sum.txt~
7)mv:移动某个文件或目录
-i:提示。
-f:强制移动。
-u:新覆盖旧,不存在时移动。
① 将同一个文件,移动到同级目录下,必须修改文件名,效果相当于重命名。
[root@image_boundary Desktop]# ll total 8 drwxr-xr-x. 2 root root 4096 Oct 15 21:55 aa drwxr-xr-x. 2 root root 4096 Oct 15 21:54 bb [root@image_boundary Desktop]# mv bb/sum.txt bb/sum1.txt
② 将同一个文件,移动到不同目录下,如果没有指定新文件名,效果相当于移动。
此操作,仅相当于把sum.txt移动到aa目录下。
[root@image_boundary Desktop]# mv bb/sum.txt aa/
③ 将同一个文件,移动到不同目录下,可以不用修改文件名。
如果指定了新文件名,效果相当于移动+重命名。 [root@image_boundary Desktop]# mv bb/sum.txt aa/sum.txt "把bb目录下的sum.txt文件,移动到aa目录下,并重命名为sum1.txt。" [root@image_boundary Desktop]# mv bb/sum.txt aa/sum1.txt
8)head/tail:展示开头或者结尾的若干行,默认10行
-n :指定行数;
head :查看文件中所有内容;
tail :查看文件中所有内容;
head -n:查看前n行数据;
tail -n:查看后n行数据;
“在计划任务那里会用下面这个参数。”
“在hadoop集群里面,查看log日志文件的时候,会用到。”
tail -f:查看新追加内容;
操作如下:
[root@image_boundary Desktop]# ll total 8 drwxr-xr-x. 2 root root 4096 Oct 15 22:35 aa drwxr-xr-x. 2 root root 4096 Oct 15 22:30 bb [root@image_boundary Desktop]# head -3 aa/sum.txt aaaaaaaaaaaaaaaaa bbbbbbbbbbbbbbbbb ccccccccccccccccc [root@image_boundary Desktop]# tail -3 aa/sum.txt mmmmmmmmmmmmmmmmm nnnnnnnnnnnnnnnnn ooooooooooooooooo