操作集群
基本语法
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] <localsrc> ... <dst>]
[-copyToLocal [-p] [-ignoreCrc] [-crc] <src> ... <localdst>]
[-count [-q] [-h] <path> ...]
[-cp [-f] [-p | -p[topax]] <src> ... <dst>]
[-createSnapshot <snapshotDir> [<snapshotName>]]
[-deleteSnapshot <snapshotDir> <snapshotName>]
[-df [-h] [<path> ...]]
[-du [-s] [-h] <path> ...]
[-expunge]
[-find <path> ... <expression> ...]
[-get [-p] [-ignoreCrc] [-crc] <src> ... <localdst>]
[-getfacl [-R] <path>]
[-getfattr [-R] {-n name | -d} [-e en] <path>]
[-getmerge [-nl] <src> <localdst>]
[-help [cmd ...]]
[-ls [-d] [-h] [-R] [<path> ...]]
[-mkdir [-p] <path> ...]
[-moveFromLocal <localsrc> ... <dst>]
[-moveToLocal <src> <localdst>]
[-mv <src> ... <dst>]
[-put [-f] [-p] [-l] <localsrc> ... <dst>]
[-renameSnapshot <snapshotDir> <oldName> <newName>]
[-rm [-f] [-r|-R] [-skipTrash] <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 ...]]
常用命令
(0) 启动Hadoop集群(方便后续的测试)
# sbin/start-dfs.sh
# sbin/start-yarn.sh
(1) -help:输出这个命令参数
# bin/hadoop fs -help rm
(2) 本地 -> HDFS
- -copyFromLocal:从本地文件系统中拷贝文件到hdfs路径去
- -put:等同于copyFromLocal
# bin/hadoop fs -copyFromLocal test.txt /yankai/test/
# bin/hadoop fs -put test1.txt /yankai/test/
(3) HDFS -> 本地
- -copyToLocal:从hdfs拷贝到本地
- -get:等同于copyToLocal,就是从hdfs下载文件到本地
# bin/hadoop fs -copyToLocal /yankai/test/test1.txt ./test01.txt
# bin/hadoop fs -get /yankai/test/test1.txt ./test02.txt
(4) HDFS文件系统操
- -mkdir:在hdfs上创建目录
# bin/hadoop fs -mkdir -p /yankai/user
# bin/hadoop fs -mkdir -p /yankai/input
# bin/hadoop fs -mkdir -p /yankai/test
- -ls: 显示目录信息
# bin/hadoop fs -ls /
# bin/hadoop fs -ls -R /
- -appendToFile :追加一个文件到已经存在的文件末尾
# bin/hadoop fs -appendToFile test.txt /yankai/test/test01.txt
- -cat :显示文件内容
# bin/hadoop fs -cat /yankai/test/test01.txt
- -tail:显示一个文件的末尾
# bin/hadoop fs -tail /yankai/test/test01.txt
- -chgrp 、-chmod、-chown:linux中的用法一样,修改文件所属权限
# bin/hadoop fs -chmod 777 /yankai/test/test.txt
bin/hadoop fs -chown root:root /yankai/test/test.txt
- -cp :从hdfs的一个路径拷贝到hdfs的另一个路径
# bin/hadoop fs -cp /yankai/test/test01.txt /
- -mv:在hdfs目录中移动文件
# bin/hadoop fs -mv /yankai/test/test1.txt /
- -getmerge :合并下载多个文件,比如hdfs的目录/aaa/下有多个文件
# bin/hadoop fs -getmerge /yankai/test/* ./new.txt
- -rm:删除文件或文件夹
# bin/hadoop fs -rm /test1.txt
- -rmdir:删除空目录
# bin/hadoop fs -rmdir /user/yankai/input
- -df :统计文件系统的可用空间信息
# bin/hadoop fs -df /
- -du统计文件夹的大小信息
# bin/hadoop fs -du /
- -setrep:设置hdfs中文件的副本数量
# bin/hadoop fs -setrep 2 /yankai/test/test.txt