当前位置:网站首页>第2章 HFDS的Shell操作
第2章 HFDS的Shell操作
2022-07-06 09:29:00 【留不住斜阳】
2.1 基本语法
hadoop fs 具体命令
或
hdfs dfs 具体命令
2.2 命令大全
具体命令如下
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] [-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>]
[-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> ...]
[-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]
2.3 常用命令
注意:如果提示root权限不能进行写操作,请切换到hdfs用户操作
2.3.1 -help
帮助命令
hadoop fs -help rm
或
hdfs dfs -help rm
注意:hadoop脚本、hdfs脚本,在hadoop安装目录的bin目录下
2.3.2 -ls
显示目录信息
hadoop fs -ls /
或
hdfs dfs –ls /
2.3.3 -mkdir
在hdfs上创建目录
hadoop fs -mkdir -p /teaching/hdfs
或
hdfs dfs -mkdir -p /teaching/hdfs
2.3.4 -moveFromLocal
从本地剪切后粘贴到hdfs
touch test.txt
hadoop fs -moveFromLocal ./test.txt /teaching/hdfs
或
hdfs dfs –moveFromLocal ./test.txt /teaching/hdfs
注意:执行过程为先复制,后删除,如果hdfs用户不具有删除本地文件权限则复制到hdfs能成功,删除本地文件不能成功
2.3.5 -appendToFile
追加一个文件到已经存在的文件末尾
touch test2.txt
vi test2.txt
# 输入
hello hdfs
hadoop fs -appendToFile test2.txt /teaching/hdfs/test.txt
或
hdfds dfs -appendToFile test2.txt /teaching/hdfs/test.txt
2.3.6 -cat
查看文件内容
hadoop fs -cat /teaching/hdfs/test.txt
或
hdfs dfs –cat /teaching/hdfs/test.txt
2.3.7 -tail
显示文件最后1kb内容
hadoop fs -tail /teaching/hdfs/test.txt
或
hdfs dfs -tail /teaching/hdfs/test.txt
2.3.8 -chgrp、-chmod、-chown
修改文件所属组、权限、用户
- 修改HDFS存储的文件/teaching/hdfs/tt.txt文件所属组,默认组:supergroup选项-R递归执行
$ hdfs dfs -ls /teaching/hdfs
-rw-r--r-- 3 hdfs supergroup 11 2019-08-12 14:40 /teaching/hdfs/tt.txt
$ hdfs dfs -chgrp lubin-group /teaching/hdfs/tt.txt
$ hdfs dfs -ls /teaching/hdfs
-rw-r--r-- 3 hdfs lubin-group 11 2019-08-12 14:40 /teaching/hdfs/tt.txt
- 修改HDFS存储的文件/teaching/hdfs/tt.txt文件的权限
$ hdfs dfs -chmod 666 /teaching/hdfs/tt.txt
$ hdfs dfs -ls /teaching/hdfs
-rw-rw-rw- 3 hdfs lubin-group 11 2019-08-12 14:40 /teaching/hdfs/tt.txt
- 修改HDFS存储的文件/teaching/hdfs/tt.txt文件所属的用户和组,lubin1为用户,lubin2为组
$ hdfs dfs -chown lubin1:lubin2 /teaching/hdfs/tt.txt
$ hdfs dfs -ls /teaching/hdfs/tt.txt
-rw-rw-rw- 3 lubin1 lubin2 11 2019-08-12 14:40 /teaching/hdfs/tt.txt
2.3.9 -copyFromLocal
从本地文件系统拷贝文件到hdfs路径
hadoop fs -copyFromLocal README.txt /teaching/hdfs
或
hdfs dfs -copyFromLocal test3.txt /teaching/hdfs
2.3.10 -copyToLocal
从hdfs拷贝到本地
hadoop fs -copyToLocal /teaching/hdfs/test.txt /tmp
或
hdfs dfs –copyToLocal /teaching/hdfs/test.txt /tmp
2.3.11 -cp
从hdfs的一个路径拷贝到hdfs的另一个路径
hadoop fs -cp /teaching/hdfs/test3.txt /teaching/hdfs2
或
hdfs dfs -cp /teaching/hdfs/test3.txt /teaching/hdfs2
2.3.12 -mv
在hdfs目录中移动文件
hadoop fs -mv /teaching/hdfs/tt.txt /teaching/hdfs2
或
hdfs dfs -mv /teaching/hdfs/tt.txt /teaching/hdfs2
2.3.13 -get
等同于copyToLocal,从hdfs下载文件到本地
hadoop fs -get /teaching/hdfs/test3.txt /tmp
或
hdfs dfs -get /teaching/hdfs/test3.txt /tmp
2.3.14 -getmerge
合并下载多个文件(多个文件的内容合并到一个文件中),比如hdfs的目录/aaa/下有多个文件:log.1, log.2,log.3,…
hadoop fs -getmerge /teaching/hdfs/log*.txt /tmp/log.txt
或
hdfs dfs -getmerge /teaching/hdfs/log*.txt /tmp/log.txt
2.3.15 -put
等同于copyFromLocal
hadoop fs -put log1.txt /teaching/hdfs
或
hdfs dfs –put log1.txt /teaching/hdfs
2.3.16 -rm
删除文件或文件夹
hadoop fs -rm /teaching/hdfs2/log1.txt
或
hdfs dfs –rm /teaching/hdfs2/log2.txt
注意:如果用户没有删除的权限,可以使用如下方式删除:su hdfs -c “hadoop fs -rm /test/test.txt”
2.3.17 -rmdir
删除空目录
hadoop fs -rmdir /test
或
hdfs dfs –rmdir /test
注意:上述命令只能删除空目录,删除非空目录用rm命令
2.3.18 -du
统计文件夹的大小信息
hadoop fs -du -s -h /teaching/hdfs
或
hdfs dfs -du -s -h /teaching/hdfs
58 174 /teaching/hdfs
注意:-s显示总(摘要)大小,去掉-s则显示每个匹配的文件大小;
-h以人类可读的方式格式化大小,不是用字节去展示;
第一列显示目录下总文件大小,第二列标示该目录下所有文件在集群上的总存储大小(与副本数有关),第三列是查询的目录名称
2.3.19 -setrep
设置hdfs中文件的副本数量
hadoop fs -setrep 10 /teaching/hdfs/test.txt
或
hdfs dfs –setrep 2 /teaching/hdfs /test.txt
设置的副本数只是记录在NameNode的元数据中,是否真的会有这么多副本,还得看DataNode的数量。因为目前只有3台设备,最多也就3个副本,如果设置为10,只有节点数的增加到10台时,副本数才能达到10。
边栏推荐
- 1605. Sum the feasible matrix for a given row and column
- VMware Tools和open-vm-tools的安装与使用:解决虚拟机不全屏和无法传输文件的问题
- QT实现窗口渐变消失QPropertyAnimation+进度条
- js时间函数大全 详细的讲解 -----阿浩博客
- QT simulates mouse events and realizes clicking, double clicking, moving and dragging
- Codeforces Round #797 (Div. 3)无F
- Research Report on market supply and demand and strategy of double drum magnetic separator industry in China
- Pytorch extract skeleton (differentiable)
- Effet d'utilisation, déclenché lorsque les composants de la fonction sont montés et déchargés
- Oneforall installation and use
猜你喜欢
随机推荐
QT实现圆角窗口
Log statistics (double pointer)
Share an example of running dash application in raspberry pie.
The "sneaky" new asteroid will pass the earth safely this week: how to watch it
1605. Sum the feasible matrix for a given row and column
Acwing: Game 58 of the week
解决Intel12代酷睿CPU单线程只给小核运行的问题
第 300 场周赛 - 力扣(LeetCode)
日期加1天
SF smart logistics Campus Technology Challenge (no T4)
How to insert mathematical formulas in CSDN blog
树莓派4B64位系统安装miniconda(折腾了几天终于解决)
useEffect,函數組件掛載和卸載時觸發
(POJ - 3258) River hopper (two points)
Pytorch extract skeleton (differentiable)
Codeforces Round #798 (Div. 2)A~D
新手必会的静态站点生成器——Gridsome
Base dice (dynamic programming + matrix fast power)
Some problems encountered in installing pytorch in windows11 CONDA
Openwrt source code generation image