HDFS文件Shell操作命令
作者:互联网
基本格式:
-
hdfs dfs -cmd
-
hadoop fs -cmd(已过时)
查看可用命令:hdfs dfs
[root@hadoop60 ~]# hdfs dfs
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>] #本地拷贝文件到hdfs
[-copyToLocal [-p] [-ignoreCrc] [-crc] <src> ... <localdst>] #hdfs拷贝到本地
[-count [-q] [-h] [-v] [-x] <path> ...]
[-cp [-f] [-p | -p[topax]] <src> ... <dst>]
[-createSnapshot <snapshotDir> [<snapshotName>]]
[-deleteSnapshot <snapshotDir> <snapshotName>]
[-df [-h] [<path> ...]]
[-du [-s] [-h] [-x] <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 [-C] [-d] [-h] [-q] [-R] [-t] [-S] [-r] [-u] [<path> ...]]
[-mkdir [-p] <path> ...] #创建目录
[-moveFromLocal <localsrc> ... <dst>] #从本地移动到HDFS
[-moveToLocal <src> <localdst>]
[-mv <src> ... <dst>]
[-put [-f] [-p] [-l] <localsrc> ... <dst>] #上传本地文件到HDFS
[-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> ...]
[-usage [cmd ...]]
Generic options supported are
-conf <configuration file> specify an application configuration file
-D <property=value> use value for given property
-fs <local|namenode:port> specify a namenode
-jt <local|resourcemanager:port> specify a ResourceManager
-files <comma separated list of files> specify comma separated files to be copied to the map reduce cluster
-libjars <comma separated list of jars> specify comma separated jar files to include in the classpath.
-archives <comma separated list of archives> specify comma separated archives to be unarchived on the compute machines.
The general command line syntax is
bin/hadoop command [genericOptions] [commandOptions]
- 使用hdfs dfs -help 查看各命令的具体使用
#查看du命令的具体使用
[root@hadoop60 ~]# hdfs dfs -help du
-du [-s] [-h] [-x] <path> ... :
Show the amount of space, in bytes, used by the files that match the specified
file pattern. The following flags are optional:
-s Rather than showing the size of each individual file that matches the
pattern, shows the total (summary) size.
-h Formats the sizes of files in a human-readable fashion rather than a number
of bytes.
-x Excludes snapshots from being counted.
Note that, even without the -s option, this only shows size summaries one level
deep into a directory.
The output is in the form
size disk space consumed name(full path)
#查看mkdir命令的具体使用
[root@hadoop60 ~]# hdfs dfs -help copyFromLocal
-copyFromLocal [-f] [-p] [-l] <localsrc> ... <dst> :
Identical to the -put command.
[root@hadoop60 ~]# hdfs dfs -help mkdir
-mkdir [-p] <path> ... :
Create a directory in specified location.
-p Do not fail if the directory already exists
- 常用命令使用示例:
#启动 Hadoop 集群(方便后续的测试)
[root@hadoop101 hadoop]$ sbin/start-dfs.sh
[hadoop@hadoop103 hadoop]$ sbin/start-yarn.sh
#-help:输出这个命令参数
[root@hadoop101 hadoop]$ hdfs dfs -help rm
#-ls: 显示目录信息
[root@hadoop101 hadoop]$ hdfs dfs -ls /
#-mkdir:在 hdfs 上创建目录,-p 创建多级目录
[root@hadoop101 hadoop]$ hdfs dfs -mkdir -p /kgc/test
#-moveFromLocal 从本地剪切粘贴到 hdfs
[root@hadoop101 hadoop]$ touch hello.txt
[root@hadoop101 hadoop]$ hdfs dfs -moveFromLocal ./hello.txt /kgc/test
#--appendToFile :追加一个文件到已经存在的文件末尾
[root@hadoop101 hadoop]$ touch test1.txt
[root@hadoop101 hadoop]$ vi test1.txt
#输入:
hadoop spark
flink spark
[root@hadoop101 hadoop]$ hdfs dfs -appendToFile test1.txt /kgc/test/hello.txt
# -cat :显示文件内容
[root@hadoop101 hadoop]$ hdfs dfs -cat /kgc/test/hello.txt
# -tail:显示一个文件的末尾
[root@hadoop101 hadoop]$ hdfs dfs -tail /kgc/test/hello.txt
# -chgrp 、-chmod、-chown:linux 文件系统中的用法一样,修改文件所属权限
[root@hadoop101 hadoop]$ hdfs dfs -chmod 666 /kgc/test/hello.txt
[root@hadoop101 hadoop]$ hdfs dfs -chown kgc:kgc /kgc/test/hello.txt
#-copyFromLocal:从本地文件系统中拷贝文件到 hdfs 路径去
[root@hadoop101 hadoop]$ hdfs dfs -copyFromLocal README.txt /
# -copyToLocal:从 hdfs 拷贝到本地
[root@hadoop101 hadoop]$ hdfs dfs -copyToLocal
/kgc/test/hello.txt ./
# -cp :从 hdfs 的一个路径拷贝到 hdfs 的另一个路径
[root@hadoop101 hadoop]$ hdfs dfs -cp /kgc/test/hello.txt
/hello1.txt
# -mv:在 hdfs 目录中移动文件
[root@hadoop101 hadoop]$ hdfs dfs -mv /hello1.txt /kgc/test/
# -get:等同于 copyToLocal,就是从 hdfs 下载文件到本地
[root@hadoop101 hadoop]$ hdfs dfs -get /kgc/test/hello.txt ./
# -getmerge :合并下载多个文件,比如 hdfs 的目录/user/kgc/test/下有多个文件:log.1, log.2,log.3,...,需要预先创建出目录,并存多个文件。
[root@hadoop101 hadoop]$ hdfs dfs -getmerge
/user/kgc/test/* ./merge.txt
# -put:等同于 copyFromLocal
[root@hadoop101 hadoop]$ hdfs dfs -put ./merge.txt /user/kgc/test/
# -rm:删除文件或文件夹
[root@hadoop101 hadoop]$ hdfs dfs -rm /user/kgc/test/merge.txt
#rmr递归删除目录下所有子目录和文件,生产环境中慎用
[root@hadoop101 hadoop]$ hdfs dfs -rmr /hdfs
# -rmdir:删除空目录
[root@hadoop101 hadoop]$ hdfs dfs -mkdir /test
[root@hadoop101 hadoop]$ hdfs dfs -rmdir /test
# -du 统计文件夹的大小信息
[root@hadoop101 hadoop]$ hdfs dfs -du -s -h /user/kgc/test
[root@hadoop101 hadoop]$ hdfs dfs -du -h /user/kgc/test
# -setrep:修改hdfs 中文件的副本数量
[root@hadoop101 hadoop]$ hdfs dfs -setrep 10 /kgc/test/hello.txt
标签:HDFS,Shell,操作命令,...,hdfs,hadoop,dfs,hadoop101,root 来源: https://blog.csdn.net/weixin_48185778/article/details/110444031