基本命令
hadoop fs 具体命令
参数大全
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] [-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 ...]]
常用命令
- -help,输出这个命令参数
hadoop fs -help ls - -ls,显示目录信息
hadoop fs -ls / - -mkdir,在hdfs上创建目录
hadoop fs -mkdir -p /user/hadoop/test - -moveFromLocal,从本地剪切粘贴到hdfs
hadoop fs -moveFromLocal hello.txt /user/hadoop/test - -appendToFile,追加一个文件到已经存在的文件末尾
hadoop fs -appendToFile hello.txt /user/hadoop/test/hello.txt - -cat,显示文件内容
hadoop fs -cat /user/hadoop/test/hello.txt - -tail,显示一个文件的末尾
hadoop fs -tail /user/hadoop/test/hello.txt - -chgrp、-chmod、-chown,同linux文件系统中的用法一样,修改文件所属权限
- -copyFromLocal,从本地文件系统中拷贝文件到hdfs路径去
hadoop fs -copyFromLocal test.txt /user/hadoop/test/ - -copyToLocal,从hdfs拷贝文件到本地
hadoop fs -copyToLocal /user/hadoop/test/hello.txt hdfsHello.txt - -cp,从hdfs的一个路径拷贝到hdfs的另一个路径
hadoop fs -cp /user/hadoop/test/hello.txt /user/hadoop/test/cpHello.txt - -mv,在hdfs目录中移动文件
hadoop fs -mv /user/hadoop/hello.txt /user/hadoop/test/mvHello.txt - -get,等同于copyToLocal,就是从hdfs下载文件到本地
hadoop fs -get /user/hadoop/test/ .
hadoop fs -get /user/hadoop/test/test.txt .
hadoop fs -get /user/hadoop/test/test.txt renametest.txt - -getmerge,合并下载多个文件
hadoop fs -getmerge /user/hadoop/test/ getmerge.txt - -put,等同于copyFromLocal
hadoop fs -put /user/hadoop/test/hello.txt hdfsHello.txt - -rm,删除文件或文件夹
hadoop fs -rm -r /user/hadoop/test/
hadoop fs -rm /user/hadoop/hadoop-2.8.3.tar.gz - -rmdir,删除空目录
hadoop fs -rmdir /user/hadoop/ -
-du,统计文件夹的大小信息
hadoop fs -du -s -h /user/hadoop/test/
hadoop fs -du -h /user/hadoop/test/hadoop du命令.png
-
-setrep,设置hdfs中文件的副本数量
hadoop fs -setrep 10 /user/hadoop/test/jdk-8u181-linux-x64.tar.gzhadoop setrep.png
这里设置的副本数只是记录在NameNode的元数据中,是否真的会有这么多副本,还得看DataNode的数量。因为目前只有3台设备,最多也就3个副本,只有节点数的增加到10台时,副本数才能达到10。