1. 上传 -put
-moveFromLocal/-copyFromLocal/-put/-appendToFile
- moveFromLocal:从本地剪切并粘贴到hdfs
- copyFromLocal/put:从本地复制并粘贴到hdfs
- appendToFile:追加一个文件到已经存在的文件末尾
# hadoop fs -moveFromLocal 本地文件目录 hdfs目标目录
hadoop fs -moveFromLocal a.txt /
#追加b.txt的内容到a.txt中
hadoop fs -appendToFile b.txt /a.txt
2. 下载 -get
-copyToLocal/get/getmerge
- copyToLocal/get:将hdfs中的文件拷贝下来
- getmerge:合并下载多个文件
# hdfs中的文件a.txt,b.txt 合并为c.txt,且下载到本地当前目录
hadoop fs -getmerge /a.txt /b.txt c.txt
3. hdfs中文件复制移动 -mv
-cp/mv
- cp: 复制hdfs某个文件到某个目录
- mv: 剪切hdfs某个文件到某个目录
# 将a.txt.20220718文件移动到test目录
hadoop fs -mv /a.txt.20220718 /test
4. 删除 -rm
-rm
rm 可以删除文件或者目录
# 删除a1.txt文件
hadoop fs -rm /a1.txt
# 删除目录/test
hadoop fs -rm -r /test
5. hdfs文件查看 -tail
-tail/cat/text
- tail : 查看文件末尾几行
- cat/text : 显示文件内容
6. hdfs文件权限 chmod
-chgrp 、-chmod、-chown
用法和Linux一样
# 对b.txt修改为可读可写可执行
hadoop fs -chmod 777 /b.txt
-rwxrwxrwx 1 mayi mayi 22 2022-07-18 07:28 /b.txt
7. 统计文件大小
du/df
# 统计根目录总大小
hadoop fs -du -s -h /
# 统计根目录各个子目录大小
hadoop fs -du -h /
22 /b.txt
5.0 M /directory
107 /exdata
24.4 K /flume
203.7 M /gulivideo
29.6 K /hbase
0 /historyLog
655.3 M /opt
3.8 G /other
162 /spark_sql_data
62.5 M /tmp
200.4 M /user
182 /wc
df
# 查看hdfs磁盘大小
hadoop fs -df -h /
Filesystem Size Used Available Use%
hdfs://mayi101:9000 51.0 G 5.0 G 25.7 G 10%