日期:2014-05-16  浏览次数:20902 次

[综合]Apache Hadoop 2.2.0文件系统shell(二)[翻译]

cp

用法:

hdfs dfs -cp [-f] URI [URI ...] <dest>

从源文件拷贝到目标文件,支持多源文件操作不过目标需要是目录。-f选项如果目标存在就会覆盖。如:

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 [-s] [-h] URI [URI ...]

展示目录包括的文件和目录大小,如果是文件的话那么就是他的size。

选项:

-s 展示文件合计大小
-h 格式化显示 如 64.0m标示 67108864

例子:

hdfs dfs -du /user/hadoop/dir1 /user/hadoop/file1 hdfs://nn.example.com/user/hadoop/dir1

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

dus

用法:

 hdfs dfs -dus <args>

展示文件大小,等同于?hdfs dfs -du -s

expunge

用法:

hdfs dfs -expunge

清空hdfs的垃圾箱,更多信息参考hdfs的架构设计

get

用法:

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

拷贝文件到本地,-ignorecrc会拷贝CRC检测失败的文件,-crc可以使得CRC和文件一起被拷贝,例如:

hdfs dfs -get /user/hadoop/file localfile
hdfs dfs -get hdfs://nn.example.com/user/hadoop/file localfile

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

getmerge

用法:

hdfs dfs -getmerge <src> <localdst> [addnl]

源文件和目标文件作为输入,将源文件中的所有文件合并成一个本地文件,addnl可选,用于在每个文件的结尾加一个换行符。

ls

用法:

 hdfs dfs -ls <args>

文件的话返回如下格式:

permissions number_of_replicas userid groupid filesize modification_date modification_time filename

目录的话罗列其子文件跟unix类似,格式如下:

permissions userid groupid modification_date modification_time dirname

例子如下:

hdfs df