Hadoop-2.2.0中文文档—— Shell命令

FS Shell

调用文件系统(FS)Shell命令应使用 bin/hadoop fs <args>的形式。 全部的的FS shell命令使用URI路径作为參数。URI格式是scheme://authority/path。

对HDFS文件系统,scheme是hdfs。对本地文件系统,scheme是file。

当中scheme和authority參数都是可选的,如果未加指定,就会使用配置中指定的默认scheme。

一个HDFS文件或文件夹比方/parent/child能够表示成hdfs://namenode:namenodeport/parent/child,或者更简单的/parent/child(如果你配置文件里的默认值是namenode:namenodeport)。

大多数FS Shell命令的行为和相应的Unix Shell命令类似,不同之处会在以下介绍各命令使用详情时指出。出错信息会输出到stderr,其它信息输出到stdout。

appendToFile——新增命令

使用方法: hdfs dfs -appendToFile <localsrc> ... <dst>

从本地文件系统追加单 源,或多源 到目的文件系统。也从标准输入读取并追加到目的文件系统。

  • hdfs dfs -appendToFile localfile /user/hadoop/hadoopfile
  • hdfs dfs -appendToFile localfile1 localfile2 /user/hadoop/hadoopfile
  • hdfs dfs -appendToFile localfile hdfs://nn.example.com/hadoop/hadoopfile
  • hdfs dfs -appendToFile - hdfs://nn.example.com/hadoop/hadoopfile Reads the input from stdin.

返回值:
成功返回0,失败返回-1。

cat

用法:hdfs dfs -cat URI [URI …]

将路径指定文件的内容输出到stdout。

演示样例:

  • hdfs dfs -cat hdfs://host1:port1/file1 hdfs://host2:port2/file2
  • hdfs dfs -cat file:///file3 /user/hadoop/file4

返回值:
成功返回0。失败返回-1。

chgrp

用法:hdfs dfs -chgrp [-R] GROUP URI [URI …] Change group association of files. With -R, make the change recursively through the directory structure. The user must be the owner of files, or else a super-user. Additional information is in the Permissions User Guide. -->

改变文件所属的组。

使用-R将使改变在文件夹结构下递归进行。

命令的使用者必须是文件的全部者或者超级用户。

很多其它的信息请參见HDFS权限用户指南

chmod

用法:hdfs dfs -chmod [-R] <MODE[,MODE]... | OCTALMODE> URI [URI …]

改变文件的权限。

使用-R将使改变在文件夹结构下递归进行。

命令的使用者必须是文件的全部者或者超级用户。很多其它的信息请參见HDFS权限用户指南

chown

用法:hdfs dfs -chown [-R] [OWNER][:[GROUP]] URI [URI ]

改变文件的拥有者。使用-R将使改变在文件夹结构下递归进行。

命令的使用者必须是超级用户。很多其它的信息请參见HDFS权限用户指南

copyFromLocal

用法:hdfs dfs -copyFromLocal <localsrc> URI

除了限定源路径是一个本地文件外,和put命令相似。

copyToLocal

用法:hdfs dfs -copyToLocal [-ignorecrc] [-crc] URI <localdst>

除了限定目标路径是一个本地文件外,和get命令类似。

count——新增命令

使用方法: hdfs dfs -count [-q] <paths>

计算符合特定模式的文件夹、文件和字节的数目。有-count 的输出列例如以下: DIR_COUNT, FILE_COUNT, CONTENT_SIZE FILE_NAME

带 -count -q 的输出列入下: QUOTA, REMAINING_QUATA, SPACE_QUOTA, REMAINING_SPACE_QUOTA, DIR_COUNT, FILE_COUNT, CONTENT_SIZE, FILE_NAME

演示样例:

  • hdfs dfs -count hdfs://nn1.example.com/file1 hdfs://nn2.example.com/file2
  • hdfs dfs -count -q hdfs://nn1.example.com/file1

返回值:

成功返回0,失败返回-1。

cp

用法:hdfs dfs -cp URI [URI …] <dest>

将文件从源路径拷贝到目标路径。

这个命令同意有多个源路径。此时目标路径必须是一个文件夹。

 
演示样例:

  • hdfs dfs -cp /user/hadoop/file1 /user/hadoop/file2
  • hdfs dfs -cp /user/hadoop/file1 /user/hadoop/file2 /user/hadoop/dir

返回值:

成功返回0。失败返回-1。

du

用法:hdfs dfs -du URI [URI …]

显示文件夹中全部文件的大小,或者当仅仅指定一个文件时。显示此文件的大小。


演示样例:
hdfs dfs -du /user/hadoop/dir1 /user/hadoop/file1 hdfs://host:port/user/hadoop/dir1 
返回值:
成功返回0。失败返回-1。

 

dus

用法:hdfs dfs -dus <args>

显示文件的大小。

expunge

用法:hdfs dfs -expunge

清空回收站。请參考HDFS设计文档文档以获取很多其它关于回收站特性的信息。

get

用法:hdfs dfs -get [-ignorecrc] [-crc] <src> <localdst> 

拷贝文件到本地文件系统。

可用-ignorecrc选项复制CRC校验失败的文件。使用-crc选项拷贝文件以及CRC信息。

演示样例:

  • hdfs dfs -get /user/hadoop/file localfile
  • hdfs dfs -get hdfs://host:port/user/hadoop/file localfile

返回值:

成功返回0,失败返回-1。

getmerge

用法:hdfs dfs -getmerge <src> <localdst> [addnl]

接受一个源文件夹和一个目标文件作为输入,而且将源文件夹中全部的文件连接成本地目标文件。

addnl是可选的,用于指定在每一个文件结尾加入一个换行符。

ls

用法:hdfs dfs -ls <args>

假设是文件。则依照例如以下格式返回文件信息:
文件名称 <副本数> 文件大小 改动日期 改动时间 权限 用户ID 组ID 
假设是文件夹,则返回它直接子文件的一个列表。就像在Unix中一样。

文件夹返回列表的信息例如以下:
文件夹名 <dir> 改动日期 改动时间 权限 用户ID 组ID 
演示样例:
hdfs dfs -ls /user/hadoop/file1 /user/hadoop/file2 hdfs://host:port/user/hadoop/dir1 /nonexistentfile 
返回值:
成功返回0,失败返回-1。 

lsr

用法:hdfs dfs -lsr <args> 
ls命令的递归版本号。

类似于Unix中的ls -R

mkdir

用法:hdfs dfs -mkdir <paths> 

接受路径指定的uri作为參数,创建这些文件夹。其行为类似于Unix的mkdir -p,它会创建路径中的各级父文件夹。

演示样例:

  • hdfs dfs -mkdir /user/hadoop/dir1 /user/hadoop/dir2
  • hdfs dfs -mkdir hdfs://host1:port1/user/hadoop/dir hdfs://host2:port2/user/hadoop/dir

返回值:

成功返回0。失败返回-1。

movefromLocal

用法:dfs -moveFromLocal <src> <dst>

输出一个”not implemented“信息。

mv

用法:hdfs dfs -mv URI [URI …] <dest>

将文件从源路径移动到目标路径。这个命令同意有多个源路径,此时目标路径必须是一个文件夹。

不同意在不同的文件系统间移动文件。 
演示样例:

  • hdfs dfs -mv /user/hadoop/file1 /user/hadoop/file2
  • hdfs dfs -mv hdfs://host:port/file1 hdfs://host:port/file2 hdfs://host:port/file3 hdfs://host:port/dir1

返回值:

成功返回0,失败返回-1。

put

用法:hdfs dfs -put <localsrc> ... <dst>

从本地文件系统中复制单个或多个源路径到目标文件系统。

也支持从标准输入中读取输入写入目标文件系统。

  • hdfs dfs -put localfile /user/hadoop/hadoopfile
  • hdfs dfs -put localfile1 localfile2 /user/hadoop/hadoopdir
  • hdfs dfs -put localfile hdfs://nn.example.com/hadoop/hadoopfile
  • hdfs dfs -put - hdfs://nn.example.com/hadoop/hadoopfile 
  • 从标准输入中读取输入。

返回值:

成功返回0。失败返回-1。

rm

用法:hdfs dfs -rm URI [URI …]

删除指定的文件。

仅仅删除非空文件夹和文件。请參考rmr命令了解递归删除。


演示样例:

  • hdfs dfs -rm hdfs://host:port/file /user/hadoop/emptydir

返回值:

成功返回0,失败返回-1。

rmr

用法:hdfs dfs -rmr URI [URI …]

delete的递归版本号。
演示样例:

  • hdfs dfs -rmr /user/hadoop/dir
  • hdfs dfs -rmr hdfs://host:port/user/hadoop/dir

返回值:

成功返回0,失败返回-1。

setrep

用法:hdfs dfs -setrep [-R] <path>

改变一个文件的副本系数。-R选项用于递归改变文件夹下全部文件的副本系数。

选项:

  •  -w 要求命令等待复制完毕。这非常有可能要花非常长时间。

  •  -R  同意后向兼容. 没什么影响

演示样例:

  • hdfs dfs -setrep -w 3 -R /user/hadoop/dir1

返回值:

成功返回0。失败返回-1。

stat

用法:hdfs dfs -stat URI [URI …]

返回指定路径的统计信息。

演示样例:

  • hdfs dfs -stat path

返回值:
成功返回0,失败返回-1。

tail

用法:hdfs dfs -tail [-f] URI

将文件尾部1K字节的内容输出到stdout。

支持-f选项,行为和Unix中一致。

演示样例:

  • hdfs dfs -tail pathname

返回值:
成功返回0。失败返回-1。

test

用法:hdfs dfs -test -[ezd] URI

选项:
-e 检查文件是否存在。

假设存在则返回0。


-z 检查文件是否是0字节。假设是则返回0。

 
-d 假设路径是个文件夹。则返回1,否则返回0。

演示样例:

  • hdfs dfs -test -e filename

text

用法:hdfs dfs -text <src> 

将源文件输出为文本格式。同意的格式是zip和TextRecordInputStream。

touchz

用法:hdfs dfs -touchz URI [URI …] 

创建一个0字节的空文件。

演示样例:

  • hadoop -touchz pathname

返回值:
成功返回0,失败返回-1。

基本copy自:http://hadoop.apache.org/docs/r1.0.4/cn/hdfs_shell.html

转载于:https://www.cnblogs.com/jhcelue/p/6761471.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值