Hadoop(5):HDFS的Shell *** 作

Hadoop(5):HDFS的Shell *** 作,第1张

目录

0. 相关文章链接

1. 基本语法

2. 命令大全

3. 常用命令实 ***

3.1. 准备工作

3.2. 上传

3.3. 下载

3.4. HDFS直接 *** 作


0. 相关文章链接

Hadoop 文章汇总

1. 基本语法

hadoop fs 具体命令  OR  hdfs dfs 具体命令

两个是完全相同的。

2. 命令大全
[root@yangshibiao ~]# hadoop fs
Usage: hadoop fs [generic options]
        [-appendToFile  ... ]
        [-cat [-ignoreCrc]  ...]
        [-checksum  ...]
        [-chgrp [-R] GROUP PATH...]
        [-chmod [-R]  PATH...]
        [-chown [-R] [OWNER][:[GROUP]] PATH...]
        [-copyFromLocal [-f] [-p] [-l] [-d] [-t ]  ... ]
        [-copyToLocal [-f] [-p] [-ignoreCrc] [-crc]  ... ]
        [-count [-q] [-h] [-v] [-t []] [-u] [-x] [-e]  ...]
        [-cp [-f] [-p | -p[topax]] [-d]  ... ]
        [-createSnapshot  []]
        [-deleteSnapshot  ]
        [-df [-h] [ ...]]
        [-du [-s] [-h] [-v] [-x]  ...]
        [-expunge]
        [-find  ...  ...]
        [-get [-f] [-p] [-ignoreCrc] [-crc]  ... ]
        [-getfacl [-R] ]
        [-getfattr [-R] {-n name | -d} [-e en] ]
        [-getmerge [-nl] [-skip-empty-file]  ]
        [-head ]
        [-help [cmd ...]]
        [-ls [-C] [-d] [-h] [-q] [-R] [-t] [-S] [-r] [-u] [-e] [ ...]]
        [-mkdir [-p]  ...]
        [-moveFromLocal  ... ]
        [-moveToLocal  ]
        [-mv  ... ]
        [-put [-f] [-p] [-l] [-d]  ... ]
        [-renameSnapshot   ]
        [-rm [-f] [-r|-R] [-skipTrash] [-safely]  ...]
        [-rmdir [--ignore-fail-on-non-empty]  ...]
        [-setfacl [-R] [{-b|-k} {-m|-x } ]|[--set  ]]
        [-setfattr {-n name [-v value] | -x name} ]
        [-setrep [-R] [-w]   ...]
        [-stat [format]  ...]
        [-tail [-f] [-s ] ]
        [-test -[defsz] ]
        [-text [-ignoreCrc]  ...]
        [-touch [-a] [-m] [-t TIMESTAMP ] [-c]  ...]
        [-touchz  ...]
        [-truncate [-w]   ...]
        [-usage [cmd ...]]

Generic options supported are:
-conf         specify an application configuration file
-D                define a value for a given property
-fs  specify default filesystem URL to use, overrides 'fs.defaultFS' property from configurations.
-jt   specify a ResourceManager
-files                 specify a comma-separated list of files to be copied to the map reduce cluster
-libjars                specify a comma-separated list of jar files to be included in the classpath
-archives           specify a comma-separated list of archives to be unarchived on the compute machines

The general command line syntax is:
command [genericOptions] [commandOptions]
3. 常用命令实 *** 3.1. 准备工作

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

sbin/start-dfs.sh
sbin/start-yarn.sh

2)-help:输出这个命令参数

hadoop fs -help rm

3)创建/sanguo文件夹

hadoop fs -mkdir /sanguo
3.2. 上传

1)-moveFromLocal:从本地剪切粘贴到HDFS

vim shuguo.txt
输入:
shuguo

hadoop fs  -moveFromLocal  ./shuguo.txt  /sanguo

2)-copyFromLocal:从本地文件系统中拷贝文件到HDFS路径去

vim weiguo.txt
输入:
weiguo

hadoop fs -copyFromLocal weiguo.txt /sanguo

3)-put:等同于copyFromLocal,生产环境更习惯用put

vim wuguo.txt
输入:
wuguo

hadoop fs -put ./wuguo.txt /sanguo

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

vim liubei.txt
输入:
liubei

hadoop fs -appendToFile liubei.txt /sanguo/shuguo.txt

3.3. 下载

1)-copyToLocal:从HDFS拷贝到本地

hadoop fs -copyToLocal /sanguo/shuguo.txt ./

2)-get:等同于copyToLocal,生产环境更习惯用get

hadoop fs -get /sanguo/shuguo.txt ./shuguo2.txt
3.4. HDFS直接 *** 作

1)-ls: 显示目录信息

hadoop fs -ls /sanguo

2)-cat:显示文件内容

hadoop fs -cat /sanguo/shuguo.txt

3)-chgrp、-chmod、-chown:Linux文件系统中的用法一样,修改文件所属权限

hadoop fs  -chmod 666  /sanguo/shuguo.txt
hadoop fs  -chown  atguigu:atguigu   /sanguo/shuguo.txt

4)-mkdir:创建路径

hadoop fs -mkdir /jinguo

5)-cp:从HDFS的一个路径拷贝到HDFS的另一个路径

hadoop fs -cp /sanguo/shuguo.txt /jinguo

6)-mv:在HDFS目录中移动文件

hadoop fs -mv /sanguo/wuguo.txt /jinguo
hadoop fs -mv /sanguo/weiguo.txt /jinguo

7)-tail:显示一个文件的末尾1kb的数据

hadoop fs -tail /jinguo/shuguo.txt

8)-rm:删除文件或文件夹

hadoop fs -rm /sanguo/shuguo.txt

9)-rm -r:递归删除目录及目录里面内容

hadoop fs -rm -r /sanguo

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

hadoop fs -du -s -h /jinguo
27  81  /jinguo

hadoop fs -du  -h /jinguo
14  42  /jinguo/shuguo.txt
7   21   /jinguo/weiguo.txt
6   18   /jinguo/wuguo.tx

说明:27表示文件大小;81表示27*3个副本;/jinguo表示查看的目录

11)-setrep:设置HDFS中文件的副本数量

hadoop fs -setrep 10 /jinguo/shuguo.txt

        这里设置的副本数只是记录在NameNode的元数据中,是否真的会有这么多副本,还得看DataNode的数量。因为目前只有3台设备,最多也就3个副本,只有节点数的增加到10台时,副本数才能达到10。


注:其他Hadoop相关系列文章链接由此进 -> Hadoop 文章汇总


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/langs/719242.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-04-25
下一篇 2022-04-25

发表评论

登录后才能评论

评论列表(0条)

保存