Hadoop FS shell commands

本文详细介绍了 Hadoop 文件系统 (HDFS) 的常用命令及其使用方法,包括 appendToFile、cat、checksum、ls、mkdir 和 usage 等命令。通过具体的示例展示了如何进行文件追加、查看文件内容、获取校验和信息、列出目录内容以及创建目录等操作。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

命令格式:
hadoop fs -command -option args

appendToFile
Usage: hadoop fs -appendToFile <localsrc> ... <dst>
退出状态:
0-成功
1-失败

$ hadoop fs -appendToFile 1130.txt hadoopfile
$ hadoop fs -appendToFile - hadoopfile   #从标准输入中读取数据,然后追加到hadoopfile文件末尾
$ hadoop fs -appendToFile test.c file.txt hadoopfile  #将test.c和file.txt文件内容追加到hadoopfile文件末尾

cat
Usage: hadoop fs -cat URI [URI ...]
退出状态:
0-成功
1-失败

$ hadoop fs -cat file:///home/hadoop/file.txt hadoopfile   #file:///就表示本地文件系统的/目录

checksum
Usage: hadoop fs -checksum URI

Returns the checksum information of a file.

Example:

hadoop fs -checksum hdfs://nn1.example.com/file1
hadoop fs -checksum file:///etc/hosts


ls
Usage: hadoop fs -ls [-d] [-h] [-R] <args>

Options:

-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.
For a file ls returns stat on the file with the following format:

permissions number_of_replicas userid groupid filesize modification_date modification_time filename

For a directory it returns list of its direct children as in Unix. A directory is listed as:

permissions userid groupid modification_date modification_time dirname

Files within a directory are order by filename by default.

Example:

hadoop fs -ls /user/hadoop/file1
Exit Code:

Returns 0 on success and -1 on error.

mkdir
Usage: hadoop fs -mkdir [-p] <paths>

Takes path uri’s as argument and creates directories.

Options:

The -p option behavior is much like Unix mkdir -p, creating parent directories along the path.
Example:

hadoop fs -mkdir /user/hadoop/dir1 /user/hadoop/dir2
hadoop fs -mkdir hdfs://nn1.example.com/user/hadoop/dir hdfs://nn2.example.com/user/hadoop/dir
Exit Code:

Returns 0 on success and -1 on error.

usage
Usage: hadoop fs -usage command

Return the help for an individual command.

 

转载于:https://www.cnblogs.com/datapool/p/6139313.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值