HDFS常用命令
- 查看hadoop版本 version
hadoop version
注意,没有 ‘-’
[hadoop@master ~]$ hadoop version
Hadoop 3.3.4
Source code repository https://github.com/apache/hadoop.git -r a585a73c3e02ac62350c136643a5e7f6095a3dbb
Compiled by stevel on 2022-07-29T12:32Z
Compiled with protoc 3.7.1
From source with checksum fb9dd8918a7b8a5b430d61af858f6ec
This command was run using /usr/local/hadoop-3.3.4/share/hadoop/common/hadoop-common-3.3.4.jar
[hadoop@master ~]$
- 创建文件夹~mkdir
hadoop dfs -mkdir -p /user/hadoop
- 列出文件 -ls
hadoop dfs -ls /user
- 将本地文件拷贝到HDFS中 ~put
hdfs dfs -put /usr/local/hadoop/etc/hadoop/*.xml input
- 复制本地文件到HDFS系统中~copyFromLocal
hdfs dfs -copyFromLocal ./a.txt /user/hadoop
hdfs dfs -ls /user/hadoop
- 从HDFS下载文件到本地系统~get
hdfs dfs -get /user/hadoop/a.txt /usr/local/hadoop
还可以下载多个文件合并到下载
先用不同命令上传到hdfs中
hdfs dfs -copyFromLocal b.txt /user/hadoop
hdfs dfs -copyfromlocal b.txt /user/hadoop
hdfs dfs -get /user/hadoop/a.txt /user/hadoop/b.txt /usr/local/hadoop-3.3.4/
- 将hdfs中文件拷贝到本地~copyToLocal
hdfs dfs -copyToLocal /user/hadoop/a.txt /usr/local/hadoop-3.3.4
- 在hdfs中查看文件内容~ cat
hdfs dfs -cat /user/hadoop/a.txt
- 移动文件 ~mv
hdfs dfs -mv /user/hadoop/a.txt /user
- 在hdfs中拷贝文件 ~cp
hdfs dfs -cp /user/hadoop/b.txt /user
- 从本地移动文件~moveFromLocal
hdfs dfs -moveFromLocal ./aaaaaaa.txt
moveToLocal命令失败了
如果在 Hadoop Shell 运行这个命令,会提示功能还没实现。
moveToLocal: Option ‘-moveToLocal’ is not implemented yet.
查看文件内容跟~tail–>文件最后1KB内容
hdfs dfs -rm /user/a.txt
hdfs dfs -mkdir /user/test
根据反馈结果,rmr在最新版本中已被废弃,推荐使用 -rm -r
这风格更像是linux中的命令了
- 清空回收站~expunge
hdfs dfs -expunge
我们在HDFS系统中删除文件,其实就像是在win/linux中,文件先被放进回收站;