Hadoop HDFS学习之HDFS的常用Shell操作
【摘要】 一、基本语法bin/hadoop fs 具体命令 OR bin/hdfs dfs 具体命令dfs是fs的实现类。 二、命令大全cd /opt/module/hadoop-2.10.1/bin/hadoop fsUsage: hadoop fs [generic options] [-appendToFile <localsrc> ... <dst>] [-cat [-ignoreCrc] ...
一、基本语法
bin/hadoop fs 具体命令 OR bin/hdfs dfs 具体命令
dfs是fs的实现类。
二、命令大全
cd /opt/module/hadoop-2.10.1/
bin/hadoop fs
Usage: hadoop fs [generic options]
[-appendToFile <localsrc> ... <dst>]
[-cat [-ignoreCrc] <src> ...]
[-checksum <src> ...]
[-chgrp [-R] GROUP PATH...]
[-chmod [-R] <MODE[,MODE]... | OCTALMODE> PATH...]
[-chown [-R] [OWNER][:[GROUP]] PATH...]
[-copyFromLocal [-f] [-p] [-l] [-d] <localsrc> ... <dst>]
[-copyToLocal [-f] [-p] [-ignoreCrc] [-crc] <src> ... <localdst>]
[-count [-q] [-h] [-v] [-t [<storage type>]] [-u] [-x] <path> ...]
[-cp [-f] [-p | -p[topax]] [-d] <src> ... <dst>]
[-createSnapshot <snapshotDir> [<snapshotName>]]
[-deleteSnapshot <snapshotDir> <snapshotName>]
[-df [-h] [<path> ...]]
[-du [-s] [-h] [-x] <path> ...]
[-expunge]
[-find <path> ... <expression> ...]
[-get [-f] [-p] [-ignoreCrc] [-crc] <src> ... <localdst>]
[-getfacl [-R] <path>]
[-getfattr [-R] {-n name | -d} [-e en] <path>]
[-getmerge [-nl] [-skip-empty-file] <src> <localdst>]
[-help [cmd ...]]
[-ls [-C] [-d] [-h] [-q] [-R] [-t] [-S] [-r] [-u] [<path> ...]]
[-mkdir [-p] <path> ...]
[-moveFromLocal <localsrc> ... <dst>]
[-moveToLocal <src> <localdst>]
[-mv <src> ... <dst>]
[-put [-f] [-p] [-l] [-d] <localsrc> ... <dst>]
[-renameSnapshot <snapshotDir> <oldName> <newName>]
[-rm [-f] [-r|-R] [-skipTrash] [-safely] <src> ...]
[-rmdir [--ignore-fail-on-non-empty] <dir> ...]
[-setfacl [-R] [{-b|-k} {-m|-x <acl_spec>} <path>]|[--set <acl_spec> <path>]]
[-setfattr {-n name [-v value] | -x name} <path>]
[-setrep [-R] [-w] <rep> <path> ...]
[-stat [format] <path> ...]
[-tail [-f] <file>]
[-test -[defsz] <path>]
[-text [-ignoreCrc] <src> ...]
[-touchz <path> ...]
[-truncate [-w] <length> <path> ...]
[-usage [cmd ...]]
三、常用命令实操
1、启动Hadoop集群
在NameNode所在服务器启动hdfs:
cd /opt/module/hadoop-2.10.1/
sbin/start-dfs.sh
在ResourceManager所在服务器启动yarn:
cd /opt/module/hadoop-2.10.1/
sbin/start-yarn.sh
2、-help:输出这个命令参数
hadoop fs -help rm
3、-ls:显示目录信息
查看当前:
hadoop fs -ls /
递归查看所有:
hadoop fs -lsr /
hadoop fs -ls -R /
4、-mkdir:在HDFS上创建目录
hadoop fs -mkdir -p /sanguo/shuguo
5、-moveFromLocal:从本地剪切粘贴到HDFS
touch panjinlian.txt
vim panjinlian.txt
输入:
wo shi pan jin lian
hadoop fs -moveFromLocal ./panjinlian.txt /sanguo/shuguo
6、-appendToFile:追加一个文件到已经存在的文件末尾
touch liubei.txt
vim liubei.txt
输入:wo shi liu bei
hadoop fs -appendToFile ./liubei.txt /sanguo/shuguo/panjinlian.txt
7、-cat:显示文件内容
hadoop fs -cat /sanguo/shuguo/panjinlian.txt
8、-chgrp 、-chmod、-chown:Linux文件系统中的用法一样,修改文件所属权限
hadoop fs -chgrp liuwenqing /sanguo/shuguo/panjinlian.txt
hadoop fs -chmod 666 /sanguo/shuguo/panjinlian.txt
hadoop fs -chown liuwenqing:liuwenqing /sanguo/shuguo/panjinlian.txt
9、-copyFromLocal:从本地文件系统中拷贝文件到HDFS路径去
touch ximenqing.txt
vim ximenqing.txt
输入:wo shi xi men qing
hadoop fs -copyFromLocal ./ximenqing.txt /sanguo/shuguo/
10、-copyToLocal:从HDFS拷贝到本地
hadoop fs -copyToLocal /sanguo/shuguo/panjinlian.txt ./
11、-cp :从HDFS的一个路径拷贝到HDFS的另一个路径
hadoop fs -cp /sanguo/shuguo/panjinlian.txt /sanguo/
12、-mv:在HDFS目录中移动文件
hadoop fs -mv /sanguo/panjinlian.txt /
13、-get:等同于copyToLocal,就是从HDFS下载文件到本地
hadoop fs -get /panjinlian.txt ./
14、-getmerge:合并下载多个文件,比如HDFS的目录 /sanguo/shuguo下有多个文件:log.1, log.2,log.3,…
hadoop fs -getmerge /sanguo/shuguo/* ./zaiyiqi.txt
15、-put:等同于copyFromLocal
hadoop fs -put ./LICENSE.txt /sanguo/shuguo/
16、-tail:显示一个文件的末尾
hadoop fs -tail /sanguo/shuguo/LICENSE.txt
17、-rm:删除文件或文件夹
hadoop fs -rm /sanguo/shuguo/LICENSE.txt
18、-rmdir:删除空目录
hadoop fs -mkdir /test
hadoop fs -rmdir /test
19、-du统计文件夹的大小信息
hadoop fs -du /
hadoop fs -du -h /
hadoop fs -du -h -s /
20、-setrep:设置HDFS中文件的副本数量
hadoop fs -setrep 10 /sanguo/shuguo/panjinlian.txt
这里设置的副本数只是记录在NameNode的元数据中,是否真的会有这么多副本,还得看DataNode的数量。因为目前只有3台设备,最多也就3个副本,只有节点数的增加到10台时,副本数才能达到10。
【版权声明】本文为华为云社区用户原创内容,转载时必须标注文章的来源(华为云社区)、文章链接、文章作者等基本信息, 否则作者和本社区有权追究责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱:
cloudbbs@huaweicloud.com
- 点赞
- 收藏
- 关注作者
评论(0)