1)基本语法
bin/hadoop fs 具体命令
2)参数大全
[faded@faded102 hadoop-2.7.2]$ bin/hadoop fs
[-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] <localsrc> ... <dst>] [-copyToLocal [-p] [-ignoreCrc] [-crc] <src> ... <localdst>] [-count [-q] <path> ...] [-cp [-f] [-p] <src> ... <dst>] [-createSnapshot <snapshotDir> [<snapshotName>]] [-deleteSnapshot <snapshotDir> <snapshotName>] [-df [-h] [<path> ...]] [-du [-s] [-h] <path> ...] [-expunge] [-get [-p] [-ignoreCrc] [-crc] <src> ... <localdst>] [-getfacl [-R] <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] <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>]] [-setrep [-R] [-w] <rep> <path> ...] [-stat [format] <path> ...] [-tail [-f] <file>] [-test -[defsz] <path>] [-text [-ignoreCrc] <src> ...] [-touchz <path> ...] [-usage [cmd ...]] |
3)常用命令实操
(0)启动Hadoop集群(方便后续的测试)
[faded@ faded 102 hadoop-2.7.2]$ sbin/start-dfs.sh
[faded @ faded 103 hadoop-2.7.2]$ sbin/start-yarn.sh
(1)-help:输出这个命令参数
[faded @ faded 102 hadoop-2.7.2]$ hadoop fs -help rm
(2)-ls: 显示目录信息
[faded @ faded 102 hadoop-2.7.2]$ hadoop fs -ls /
(3)-mkdir:在hdfs上创建目录
[faded @ faded 102 hadoop-2.7.2]$ hadoop fs -mkdir -p /user/atguigu/test
(4)-moveFromLocal从本地剪切粘贴到hdfs
[atguigu@hadoop102 hadoop-2.7.2]$ touch jinlian.txt
[faded@faded 102 hadoop-2.7.2]$ hadoop fs -moveFromLocal ./jinlian.txt /user/atguigu/test
(5)--appendToFile :追加一个文件到已经存在的文件末尾
[faded @ faded 102 hadoop-2.7.2]$ touch ximen.txt
[faded @ faded 102 hadoop-2.7.2]$ vi ximen.txt
输入
wo ai jinlian
[faded@faded102 hadoop-2.7.2]$ hadoop fs -appendToFile ximen.txt /user/faded/test/jinlian.txt
(6)-cat :显示文件内容
(7)-tail:显示一个文件的末尾
[faded@faded102 hadoop-2.7.2]$ hadoop fs -tail /user/faded/test/jinlian.txt
(8)-chgrp 、-chmod、-chown:linux文件系统中的用法一样,修改文件所属权限
[faded@faded102 hadoop-2.7.2]$ hadoop fs -chmod 666 /user/faded/test/jinlian.txt
[atguigu@faded102hadoop-2.7.2]$ hadoop fs -chown atguigu:atguigu /user/faded/test/jinlian.txt
(9)-copyFromLocal:从本地文件系统中拷贝文件到hdfs路径去
[faded@faded102 hadoop-2.7.2]$ hadoop fs -copyFromLocal README.txt /user/faded/test
(10)-copyToLocal:从hdfs拷贝到本地
[faded@faded102hadoop-2.7.2]$ hadoop fs -copyToLocal /user/faded/test/jinlian.txt ./jinlian.txt
(11)-cp :从hdfs的一个路径拷贝到hdfs的另一个路径
[faded@faded102 hadoop-2.7.2]$ hadoop fs -cp /user/faded/test/jinlian.txt /jinlian2.txt
(12)-mv:在hdfs目录中移动文件
[faded@hadoop102 hadoop-2.7.2]$ hadoop fs -mv /jinlian2.txt /user/faded/test/
(13)-get:等同于copyToLocal,就是从hdfs下载文件到本地
[faded@faded102 hadoop-2.7.2]$ hadoop fs -get /user/faded/test/jinlian2.txt ./
(14)-getmerge :合并下载多个文件,比如hdfs的目录 /aaa/下有多个文件:log.1, log.2,log.3,...
[faded@faded102 hadoop-2.7.2]$ hadoop fs -getmerge /user/faded/test/* ./zaiyiqi.txt
(15)-put:等同于copyFromLocal
[faded@faded102 hadoop-2.7.2]$ hadoop fs -put ./zaiyiqi.txt /user/faded/test/
(16)-rm:删除文件或文件夹
[atguigu@hadoop102 hadoop-2.7.2]$ hadoop fs -rm /user/atguigu/test/jinlian2.txt
(17)-rmdir:删除空目录
[faded@faded102 hadoop-2.7.2]$ hadoop fs -mkdir /test
[faded@faded102 hadoop-2.7.2]$ hadoop fs -rmdir /test
(18)-df :统计文件系统的可用空间信息
[faded@faded102 hadoop-2.7.2]$ hadoop fs -df -h /
(19)-du统计文件夹的大小信息
[faded@faded102 hadoop-2.7.2]$ hadoop fs -du -s -h /user/faded/test
2.7 K /user/faded/test
[faded@faded102 hadoop-2.7.2]$ hadoop fs -du -h /user/faded/test
1.3 K /user/faded/test/README.txt
15 K /user/faded/test/jinlian.txt
1.4 K /user/faded/test/zaiyiqi.txt
(20)-setrep:设置hdfs中文件的副本数量
[faded@faded102 hadoop-2.7.2]$ hadoop fs -setrep 2 /user/faded/test/jinlian.txt
这里设置的副本数只是记录在namenode的元数据中,是否真的会有这么多副本,还得看datanode的数量。因为目前只有3台设备,最多也就3个副本,只有节点数的增加到10台时,副本数才能达到10。