Hadoop常用命令
文件路径增删改查
hdfs dfs -mkdir dir # 创建文件夹
hdfs dfs -rmr dir # 删除文件夹dir
hdfs dfs -ls # 查看目录文件信息
hdfs dfs -lsr # 递归查看文件目录信息
hdfs dfs -stat path # 返回指定路径的信息
空间大小查看
hdfs dfs -du -h dir # 人性化显示文件大小
hdfs dfs -dus uri # 递归显示目标文件的大小
hdfs dfs -du path/file # 显示目标文件file的大小
文件操作(上传下载复制)
hdfs dfs -touchz a.txt # 创建长度为0的空文件a.txt
hdfs dfs -rm file # 删除文件file
hdfs dfs -put file dir # 向dir上传file文件
hdfs dfs -put filea dir/fileb # 上传filea并改名为fileb
hdfs dfs -get file dir # 下载file到本地文件夹
hdfs dfs -getmerge hdfs://Master:9000/data/SogouResult.txt CombinedResult
# 合并hdfs多个文件到本地
hdfs dfs -cat file # 查看文件file
hdfs fs -text /dir/a.txt # 查看文本文件,压缩文件会先解压
hdfs fs -tail /dir/a.txt # 查看文件最后1000字节
hdfs dfs -copyFromLocal localsrc path # 从本地复制文件到hdfs
hdfs dfs -copyToLocal /hdfs/a.txt /local/a.txt # 从hdfs拷贝到本地
hdfs dfs -cp /dir/source /dir/target # 从原路径拷贝到目标路径
hdfs dfs -mv /path/a.txt /path/b.txt # 移动文件,可用于回收站恢复