HDFS常用命令

HDFS:它是一个文件系统,用于存储文件。它是分布式的。由多台服务器联合实现功能。适合一次写入,多次读出的场景,不支持文件修改,适合做数据分析,不适合做网盘应用。

 

HDFS架构图

 

 

 常用命令

0)启动 Hadoop 集群(方便后续的测试)

  [atguigu@hadoop102 hadoop-2.7.2]$ sbin/start-dfs.sh

 [atguigu@hadoop103 hadoop-2.7.2]$ sbin/start-yarn.sh

1-help:输出这个命令参数

  [atguigu@hadoop102 hadoop-2.7.2]$ hadoop fs -help rm

 2-ls: 显示目录信息

 [atguigu@hadoop102 hadoop-2.7.2]$ hadoop fs -ls /

3-mkdir:在 hdfs 上创建目录

 [atguigu@hadoop102 hadoop-2.7.2]$ hadoop fs -mkdir -p /user/atguigu/test

4-moveFromLocal 从本地剪切粘贴到 hdfs

 [atguigu@hadoop102 hadoop-2.7.2]$ touch jinlian.txt

 [atguigu@hadoop102 hadoop-2.7.2]$ hadoop fs  -moveFromLocal  ./jinlian.txt  

/user/atguigu/test

5--appendToFile  :追加一个文件到已经存在的文件末尾

[atguigu@hadoop102 hadoop-2.7.2]$ touch ximen.txt

[atguigu@hadoop102 hadoop-2.7.2]$ vi ximen.txt

输入

wo ai  jinlian

[atguigu@hadoop102 hadoop-2.7.2]$ hadoop fs -appendToFile ximen.txt

/user/atguigu/test/jinlian.txt

6-cat :显示文件内容

7-tail:显示一个文件的末尾

[atguigu@hadoop102 hadoop-2.7.2]$ hadoop fs -tail /user/atguigu/test/jinlian.txt

8-chgrp -chmod-chownlinux 文件系统中的用法一样,修改文件所属权限

[atguigu@hadoop102 hadoop-2.7.2]$ hadoop fs  -chmod  666  

/user/atguigu/test/jinlian.txt

[atguigu@hadoop102 hadoop-2.7.2]$ hadoop fs  -chown  atguigu:atguigu   

/user/atguigu/test/jinlian.txt

9-copyFromLocal:从本地文件系统中拷贝文件到 hdfs 路径去

[atguigu@hadoop102 hadoop-2.7.2]$ hadoop fs -copyFromLocal README.txt

/user/atguigu/test

10-copyToLocal:从 hdfs 拷贝到本地

[atguigu@hadoop102 hadoop-2.7.2]$ hadoop fs -copyToLocal

/user/atguigu/test/jinlian.txt ./jinlian.txt

11-cp :从 hdfs 的一个路径拷贝到 hdfs 的另一个路径

[atguigu@hadoop102 hadoop-2.7.2]$ hadoop fs -cp /user/atguigu/test/jinlian.txt

/jinlian2.txt

12-mv:在 hdfs 目录中移动文件

[atguigu@hadoop102 hadoop-2.7.2]$ hadoop fs -mv /jinlian2.txt /user/atguigu/test/

13-get:等同于 copyToLocal,就是从 hdfs 下载文件到本地

[atguigu@hadoop102 hadoop-2.7.2]$ hadoop fs -get /user/atguigu/test/jinlian2.txt ./ 14-getmerge  :合并下载多个文件,比如 hdfs 的目录 /aaa/下有多个文件:log.1, log.2,log.3,... [atguigu@hadoop102 hadoop-2.7.2]$ hadoop fs -getmerge /user/atguigu/test/* ./zaiyiqi.txt 15-put:等同于 copyFromLocal

[atguigu@hadoop102 hadoop-2.7.2]$ hadoop fs -put ./zaiyiqi.txt /user/atguigu/test/

16-rm:删除文件或文件夹

[atguigu@hadoop102 hadoop-2.7.2]$ hadoop fs -rm /user/atguigu/test/jinlian2.txt

17-rmdir:删除空目录

[atguigu@hadoop102 hadoop-2.7.2]$ hadoop fs -mkdir /test

[atguigu@hadoop102 hadoop-2.7.2]$ hadoop fs -rmdir /test

18-df :统计文件系统的可用空间信息

[atguigu@hadoop102 hadoop-2.7.2]$ hadoop fs -df -h /

19-du 统计文件夹的大小信息

[atguigu@hadoop102 hadoop-2.7.2]$ hadoop fs -du -s -h /user/atguigu/test

2.7 K  /user/atguigu/test

[atguigu@hadoop102 hadoop-2.7.2]$ hadoop fs -du  -h /user/atguigu/test

1.3 K  /user/atguigu/test/README.txt

15     /user/atguigu/test/jinlian.txt

1.4 K  /user/atguigu/test/zaiyiqi.txt 

 

posted @ 2018-08-06 15:54  一笑任逍遥  阅读(7837)  评论(0编辑  收藏  举报