HDFS 命令大全
概要
HDFS 文件系统的常用操作和普通 Linux 文件系统非常相似,如读取文件,新建目录,移动文件,删除数据,列出目录等。
本文只列出常用的 HDFS 命名,要查看完整的命令行列表,可点击 这里
所有的 HDFS 命令都是调用 bin/hdfs 脚本完成的,它的基本用法如下
hdfs [SHELL_OPTIONS] COMMAND [GENERIC_OPTIONS] [COMMAND_OPTIONS]
hdfs 命令分成 3 种类型,分别是
- 用户命令
- 集群管理员命令
- 调试命令(集群管理员使用)
在命令中会有一些 URI 参数,其中 URI 的前缀是由 core-site.xml 中的 fs.defaultFS 决定的,通过该属性就可以知道 namenode 在哪里运行进而连接到它。例如:
<property>
<name>fs.defaultFS</name>
<value>hdfs://hadoop2cluster</value>
</property>
而如果在本机操作,就可以省略 URI 前缀。
用户命令
dfs 命令
hdfs dfs [COMMAND [COMMAND_OPTIONS]]
hadoop 所支持的文件系统命令,其中 COMMAND_OPTIONS 可在 File System Shell Guide 查看。
hdfs dfs 命令前缀与 hadoop fs 效果相同。
追加文件内容
-appendToFile <localsrc> ... <dst>
实例
hdfs dfs -appendToFile hdfs-site.xml /tmp/tests/test.txt
查看文件内容
-cat URI [URI ...]
实例
hdfs dfs -cat /tmp/tests/test.txt
得到文件的校验信息
-checksum URI
实例
hdfs dfs -checksum /tmp/tests/test.txt
修改用户组
-chgrp [-R] GROUP URI [URI ...]
Change group association of files. The user must be the owner of files, or else a super-user. Additional information is in the Permissions Guide.
修改文件权限
-chmod [-R] <MODE[,MODE]... | OCTALMODE> URI [URI ...]
修改文件所属用户
-chown [-R] [OWNER][:[GROUP]] URI [URI ]
本地拷贝到 hdfs
-copyFromLocal <localsrc> URI
hdfs 拷贝到本地
-copyToLocal [-ignorecrc] [-crc] URI <localdst>
获取目录,文件数量及大小
-count [-q] [-h] [-v] <paths>
举例
hdfs dfs -count /tmp/tests/
得到结果
1 1 3513 /tmp/tests
其中
- 列 1 表示 目录数量
- 列 2 表示 文件数量
- 列 3 表示 文件总大小(字节)
hdfs 内拷贝
-cp [-f] [-p | -p[topax]] URI [URI ...] <dest>
-f表示如果文件已存在,会覆盖原文件-p表示会保留文件属性(时间错,owner,权限, ACL 等)
createSnapshot 创建快照
See HDFS Snapshots Guide.
deleteSnapshot 删除快照
See HDFS Snapshots Guide.
显示空闲空间
-df [-h] URI [URI ...]
-h选项会以人类友好的方式来显示,如 64M 而不是多少字节
显示文件和目录大小
-du [-s] [-h] URI [URI ...]
- The -s option will result in an aggregate summary of file lengths being displayed, rather than the individual files.
- The -h option will format file sizes in a “human-readable” fashion (e.g 64.0m instead of 67108864)
清空回收站
-expunge
Empty the Trash. Refer to the HDFS Architecture Guide for more information on the Trash feature.
查找文件
-find <path> ... <expression> ...
显示目录或文件的访问控制列表
-getfacl [-R] <path>
显示文件或目录的扩展信息
-getfattr [-R] -n name | -d [-e en] <path>
- -R: Recursively list the attributes for all files and directories.
- -n name: Dump the named extended attribute value.
- -d: Dump all extended attribute values associated with pathname.
- -e encoding: Encode values after retrieving them. Valid encodings are “text”, “hex”, and “base64”. Values encoded as text strings are enclosed in double quotes ("), and values encoded as hexadecimal and base64 are prefixed with 0x and 0s, respectively.
- path: The file or directory.
ls
-ls [-d] [-h] [-R] [-t] [-S] [-r] [-u] <args>
- -d: Directories are listed as plain files.
- -h: Format file sizes in a human-readable fashion (eg 64.0m instead of 67108864).
- -R: Recursively list subdirectories encountered.
- -t: Sort output by modification time (most recent first).
- -S: Sort output by file size.
- -r: Reverse the sort order.
- -u: Use access time rather than modification time for display and sorting.
mkdir
-mkdir [-p] <paths>
moveFromLocal
-moveFromLocal <localsrc> <dst>
moveToLocal
-moveToLocal [-crc] <src> <dst>
mv
-mv URI [URI ...] <dest>
rm
-rm [-f] [-r |-R] [-skipTrash] URI [URI ...]
- The -f option will not display a diagnostic message or modify the exit status to reflect an error if the file does not exist.
- The -R option deletes the directory and any content under it recursively.
- The -r option is equivalent to -R.
- The -skipTrash option will bypass trash, if enabled, and delete the specified file(s) immediately. This can be useful when it is necessary to delete files from an over-quota directory.
test
-test -[defsz] URI
- -d: f the path is a directory, return 0.
- -e: if the path exists, return 0.
- -f: if the path is a file, return 0.
- -s: if the path is not empty, return 0.
- -z: if the file is zero length, return 0.
tail
-tail [-f] URI
显示文件的最后的字节
- The -f option will output appended data as the file grows, as in Unix.
usage
显示命令的用法
-usage command
参考文档
HDFS 命令大全的更多相关文章
- hdfs命令大全
hdfs常用命令: 第一部分:hdfs文件系统命令 第一类:文件路径增删改查系列: hdfs dfs -mkdir dir 创建文件夹 hdfs dfs -rmr dir 删除文件夹dir hdf ...
- 【转】Hadoop命令大全
Hadoop命令大全 本节比较全面的向大家介绍一下Hadoop命令,欢迎大家一起来学习,希望通过本节的介绍大家能够掌握一些常见Hadoop命令的使用方法.下面是Hadoop命令的详细介绍. 1.列出所 ...
- Hadoop命令大全
Hadoop命令大全 分类: 云计算2011-03-01 15:04 6852人阅读 评论(0) 收藏 举报 hadoop作业任务集群class脚本 1.列出所有Hadoop Shell支持的命令 ...
- .NET Core dotnet 命令大全
dotnet 命令大全,让你理解dotnet 命令. 本文将以一个实例串起 dotnet 所有命令,让你玩转dotnet 命令. 本篇文章编写环境为windows 10 ,dotnet 命令同样适用于 ...
- CMD命令大全
有关某个命令的详细信息,请键入 HELP 命令名 ASSOC 显示或修改文件扩展名关联. AT 计划在计算机上运行的命令和程序. ATTRIB 显示或更改文件属性. BREAK 设置或清除扩展式 CT ...
- DOS命令大全!
一)MD——建立子目录 1.功能:创建新的子目录 2.类型:内部命令 3.格式:MD[盘符:][路径名]〈子目录名〉 4.使用说明: (1)“盘符”:指定要建立子目录的磁盘驱动器字母,若省略,则为当前 ...
- 黑客攻击常用CMD命令大全
黑客常用命令大全net user heibai lovechina /add 加一个heibai的用户密码为lovechina net localgroup Administrators heibai ...
- centos 命令大全
文件操作: ls ####查看目录中的文件#### ls -F ####查看目录中的文件#### ls -l ####显示文件和目录的详细资料#### ls -a ...
- db2常用命令大全
#显示这个DB2错误的解释信息(SQLSTATE 5位数字)db2 ? 42704 #显示这个SQLCODE的解释信息(SQLCODE 四位数字) db2 ? SQL0204N ##查看数据库指定配置 ...
随机推荐
- 简谈Entity Framework的优缺点
Entity Framework简介 Entity Framework的全称为 ADO.NET Entity Framework ,简称为EF, 是微软以ADO.NET为基础发展出来的实体框架,早期被 ...
- 使用wget命令爬取整站
快速上手(整个bootstrap网页全被你抓取下来了~_~) wget -c -r -npH -k -nv http://www.baidu.com 参数说明 -c:断点续传 -r:递归下载 -np: ...
- ROC,AUC,Precision,Recall,F1的介绍与计算
1. 基本概念 1.1 ROC与AUC ROC曲线和AUC常被用来评价一个二值分类器(binary classifier)的优劣,ROC曲线称为受试者工作特征曲线 (receiver operatin ...
- cad2018卸载/安装失败/如何彻底卸载清除干净cad2018注册表和文件的方法
cad2018提示安装未完成,某些产品无法安装该怎样解决呢?一些朋友在win7或者win10系统下安装cad2018失败提示cad2018安装未完成,某些产品无法安装,也有时候想重新安装cad2018 ...
- ssh登录时在参数中加入密码的解决方案
在使用ssh登录远程服务器的时候,在执行完ssh user@ip后,要输入登录密码,有时候登录密码记不住,这样以来Ian带来的很多的麻烦,有没有一种在ssh的参数中直接加入密码的方法呢?查看ssh的帮 ...
- updateByPrimaryKey 和 updateByPrimaryKeySelective
1. 数据库记录 2. updateByPrimaryKey Preparing: UPDATE t_token_info SET entity_id = ?,entity_type = ?,time ...
- js 判断 obj 是否是 数组 array
参考文章: http://www.kuitao8.com/20140511/2418.shtml function objType(obj) { //var type = Object.prototy ...
- 一步步Cobol 400 上手自学入门教程01 - 基础概念
先学习基础概念 1.COBOL字符:包含: User-defined words 用户定义字符 System-names Reserved words 关键字 2.用户定义字符User-defin ...
- 优化openfire服务器提升xmpp 效率的15个方法(原创)
1.禁用原生xmpp搜索,使组织架构.人员数据本地化保存,并使客户端数据同步服务器,降低原生xmpp搜索的iq消耗,因为搜索是im应用的频繁操作: 2.禁用roster花名册.禁用presence包通 ...
- SpaceSyntax【空间句法】之DepthMapX学习:第三篇 软件介绍与一般分析流程图
上篇讲啥来着?好像讲了数据的输入以及一些核心的概念.这篇讲软件长什么样,做那几种分析的步骤如何. 博客园/B站/知乎/CSDN @秋意正寒(我觉得这一篇肯定很多盗图的,那么我在版头加个本篇地址吧)ht ...