From 1d6b0f89284332ab516b891e2ffee1fd720697ee Mon Sep 17 00:00:00 2001 From: luoxiang <2806718453@qq.com> Date: Wed, 10 Apr 2019 22:32:09 +0800 Subject: [PATCH] =?UTF-8?q?HDFS=E5=B8=B8=E7=94=A8Shell=E5=91=BD=E4=BB=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 1 + notes/HDFS常用Shell命令.md | 138 +++++++++++++++++++++++++++++++++ 2 files changed, 139 insertions(+) create mode 100644 notes/HDFS常用Shell命令.md diff --git a/README.md b/README.md index 42c310d..7603b46 100644 --- a/README.md +++ b/README.md @@ -53,6 +53,7 @@ 2. [分布式计算框架——MapReduce](https://github.com/heibaiying/BigData-Notes/blob/master/notes/Hadoop-MapReduce.md) 3. [集群资源管理器——YARN](https://github.com/heibaiying/BigData-Notes/blob/master/notes/Hadoop-YARN.md) 4. [Hadoop单机伪集群环境搭建](https://github.com/heibaiying/BigData-Notes/blob/master/notes/installation/hadoop%E5%8D%95%E6%9C%BA%E7%89%88%E6%9C%AC%E7%8E%AF%E5%A2%83%E6%90%AD%E5%BB%BA.md) +5. [HDFS常用Shell命令](https://github.com/heibaiying/BigData-Notes/blob/master/notes/HDFS常用Shell命令.md) ## 二、Hive diff --git a/notes/HDFS常用Shell命令.md b/notes/HDFS常用Shell命令.md new file mode 100644 index 0000000..cf93d85 --- /dev/null +++ b/notes/HDFS常用Shell命令.md @@ -0,0 +1,138 @@ +# HDFS 常用 shell 命令 + +1. 显示当前目录结构 + +```shell +# 显示当前目录结构 +hadoop fs -ls +# 递归显示当前目录结构 +hadoop fs -ls -R +# 显示根目录下内容 +hadoop fs -ls / +``` + +2. 创建目录 + +```shell +# 创建目录 +hadoop fs -mkdir +# 递归创建目录 +hadoop fs -mkdir -p +``` + +3. 删除操作 + +```shell +# 删除文件 +hadoop fs -rm +# 递归删除目录和文件 +hadoop fs -rm -R +``` + +4. 从本地加载文件到HDFS + +```shell +# 二选一执行即可 +hadoop fs -put [localsrc] [dst] +hadoop fs - copyFromLocal [localsrc] [dst] +``` + + +5. 从HDFS导出文件到本地 + +```shell +# 二选一执行即可 +hadoop fs -get [dst] [localsrc] +hadoop fs -copyToLocal [dst] [localsrc] +``` + +6. 查看文件内容 + +```shell +# 二选一执行即可 +hadoop fs -text +hadoop fs -cat +``` + +7. 显示文件的最后一千字节 + +```shell +hadoop fs -tail +# 和Linux下一样,会持续监听文件内容变化 并显示文件的最后一千字节 +hadoop fs -tail -f +``` + +8. 拷贝文件 + +```shell +hadoop fs -cp [src] [dst] +``` + +9. 移动文件 + +```shell +hadoop fs -mv [src] [dst] +``` + + +10. 统计当前目录下各文件大小,单位字节。 可选参数:-s 显示所有文件大小总和,-h 显示单位 + +```shell +hadoop fs -du +``` + +11. 合并下载多个文件 ++ -nl 在每个文件的末尾添加换行符(LF) ++ -skip-empty-file 跳过空文件 + +```shell +hadoop fs -getmerge +# 示例 将HDFS上的hbase-policy.xml和hbase-site.xml文件合并后下载到本地的/usr/test.xml +hadoop fs -getmerge -nl /test/hbase-policy.xml /test/hbase-site.xml /usr/test.xml +``` + +12. 统计文件系统的可用空间信息 + +```shell +hadoop fs -df -h / +``` + +13. 更改文件复制因子 +```shell +hadoop fs -setrep [-R] [-w] +``` ++ 更改文件的复制因子。如果path是目录,则更改其下所有文件的复制因子 ++ -w : 请求命令是否等待复制完成 + +```shell +# 示例 +hadoop fs -setrep -w 3 /user/hadoop/dir1 +``` + +14. 权限控制,权限控制和Linux上使用方式一致 +```shell +# 变更文件或目录的所属群组。 用户必须是文件的所有者或超级用户。 +hadoop fs -chgrp [-R] GROUP URI [URI ...] +# 修改文件或目录的访问权限 用户必须是文件的所有者或超级用户。 +hadoop fs -chmod [-R] URI [URI ...] +# 修改文件的拥有者 用户必须是超级用户。 +hadoop fs -chown [-R] [OWNER][:[GROUP]] URI [URI ] +``` + +15. 文件检测 +```shell +hadoop fs -test - [defsz] URI +``` +可选选项: ++ -d:如果路径是目录,返回0。 ++ -e:如果路径存在,则返回0。 ++ -f:如果路径是文件,则返回0。 ++ -s:如果路径不为空,则返回0。 ++ -r:如果路径存在且授予读权限,则返回0。 ++ -w:如果路径存在且授予写入权限,则返回0。 ++ -z:如果文件长度为零,则返回0。 + +```shell +# 示例 +hadoop fs -test -e filename +``` \ No newline at end of file