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

修改文件所属组、权限、用户

  1. 修改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
  1. 修改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
  1. 修改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。

第2章 HFDS的Shell操作相关推荐

  1. 大数据技术之Hadoop(HDFS)第2章 HFDS的Shell操作

    1)基本语法 bin/hadoop fs 具体命令 2)命令大全 [atguigu@hadoop102 hadoop-2.7.2]$ bin/hadoop fs [-appendToFile < ...

  2. 【Hbase】第三章——Hbase的Shell操作与Java连接

    文章目录 任务 1.基本操作 1.1 进入客户端 1.2 namespace 1.3 DDL 1.4 DML 2. JavaApi连接Hbase 2.1 配置maven 2.2 配置log4j.pro ...

  3. Hadoop HFDS 的 Shell 操作

    调用文件系统(FS)Shell命令应使用 bin/hadoop fs 的形式. 所有的的FS shell命令使用URI路径作为参数.URI格式是scheme://authority/path.对HDF ...

  4. HFDS的Shell操作

    1.基本语法 hadoop fs 或 hdfs dfs 2.命令大全 查看命令 bin/hdfs dfs 常用基本命令操作 (1)创建新目录 查看当前目录:hdfs dfs -ls 或 hdfs df ...

  5. hbase shell命令_HBASE的shell操作

    前言 我们知道hbase其实是架构在hdfs上的一个分布式数据库,既然是数据库那么这篇文章就主要围绕着我们最熟悉的增删改查来做.当然了,其实hbase的shell操作在真实的企业中几乎不用,这个很简单 ...

  6. 二、HDFS基本架构和shell操作

    @Author : By Runsen @Date : 2020/6/20 作者介绍:Runsen目前大三下学期,专业化学工程与工艺,大学沉迷日语,Python, Java和一系列数据分析软件.导致翘 ...

  7. HDFS的Shell操作和API操作

    文章目录 HDFS的Shell操作 1.1 基本语法 1.2 命令大全 1.3 常用命令实操 1.3.1 准备工作 1.3.2 上传 1.3.3 下载 1.3.4 HDFS直接操作 第二章 HDFS客 ...

  8. 第十四章 使用SQL Shell界面(三)

    文章目录 第十四章 使用SQL Shell界面(三) SQL元数据.查询计划和性能指标 显示元数据 SHOW STATEMENT EXPLAIN and Show Plan SQL Shell Per ...

  9. 2021年大数据ZooKeeper(四):ZooKeeper的shell操作

    目录 ZooKeeper的shell操作 客户端连接 shell基本操作 操作命令 操作实例 节点属性 ​​​​​​​ZooKeeper Watcher(监听机制) ​​​​​​​Watch机制特点 ...

最新文章

  1. java visualvm远程监控_深入理解JVM虚拟机12:JVM性能管理神器VisualVM介绍与实战
  2. HttpServlet详解
  3. VC 系统托盘编程,含有气泡提示
  4. lstm 根据前文预测词_干货 | Pytorch实现基于LSTM的单词检测器
  5. 【转】SharePoint开发中可能用到的各种Context(上下文)
  6. VSS 数据库地址批量更改器 - VSS Database Changer
  7. 项目工程自动化 - OCLint
  8. linux7.2 网卡设置,CentOS 7.2网络配置
  9. Java链表——创建链表对象
  10. 5G端到端网络切片进展与挑战分析
  11. QCC3040---芯片数据手册 ADK release data sheet
  12. Win10+外接显示器 “未检测到其他显示器”
  13. 高级算法日记9:图(2)
  14. android 项目练习:自己的词典app——生词本(一)
  15. 笔记本电脑能连接WiFi但浏览器无法打开网页的解决办法
  16. deg怎么读_deg是什么意思_deg怎么读_deg翻译_用法_发音_词组_同反义词_degree(s) 度-新东方在线英语词典...
  17. vb 彩牛概率统计for Excel
  18. Python与医疗图像5
  19. 50 行 Python 代码,带你追到女神
  20. 2021-08-11记一次在线工具

热门文章

  1. python none什么意思_python – 什么是self = None?
  2. 访问swagger/Knife4j 接口文档报错:java.lang.NumberFormatException: For input string: ““
  3. 蓝牙认证,蓝牙BQB认证,蓝牙BQB测试内容,蓝牙BQB认证多少钱?蓝牙BQB认证流程
  4. 【 MES】 MES的另一视角
  5. 《Linux操作系统 - RK3288开发笔记》第3章 G-3288-02 SD卡启动及变砖恢复
  6. Android基于腾讯云的视频聊天研究
  7. springcloud整合Gateway
  8. matlab armax和arima区别,ARMA和ARIMA的区别是什么?
  9. 导览讲解 | 二维码语音讲解有什么优势?
  10. PHP学习案例9 双色球