hadoop 常见操作命令-操作手册

hadoop 常见操作命令

hadoop fs <args> = hdfs dfs <args>

hadoop fs -ls hdfs://node1:8020/
hadoop fs -ls file:///
hadoop fs -ls gfs://
1.查看指定目录下信息 -ls
hadoop fs -ls [-h] [-R] <args>
#   <args>
#   -h 人性化显示
#   -R 递归显示
#案例 显示/bai/111 目录下递归显示
hdfs dfs -ls -R /bai/111
2.创建文件夹 -mkdir
hadoop fs -mkdir [-p] <paths>
    -p 创建父目录
#案例 跨目录创建目录 /111/222/333 
hdfs dfs -mkdir -p /bai/111/222/333
3.上传文件-put 从Linux上传文件到Hadoop
hadoop fs -put src  dst
将单个 src 或多个 srcs 从本地文件系统复制到目标文件系统
    #src代表的是本地目录 所谓的本地指的是客户端所在的机器 
    #dst代表的是HDFS
    -p:保留访问和修改时间,所有权和权限。
    -f:覆盖目的地(如果已经存在)
#案例 从Linux系统将/bai/1.txt 2.txt上传到Hadoop/bai_1/目录下
hdfs dfs -put /bai/1.txt 2.txt /bai_1/
4.下载文件-get 从Hadoop下载文件到Linux
hadoop fs -get  src  localdst
    #将文件复制到本地文件系统。
#案例 把Hadoop系统中/bai_01/01.txt 02.txt 下载到Linux系统中/bai/内
hdfs dfs -get /bai_01/01.txt 02.txt /bai/
5.追加内容到文件尾部 -appendToFile
#案例 将Linux系统1.txt 2.txt 3.txt中内容追加到Hadoop中
[root@node3 ~]# echo 1 >> 1.txt
[root@node3 ~]# echo 2 >> 2.txt 
[root@node3 ~]# echo 3 >> 3.txt 
[root@node3 ~]# hadoop fs -put 1.txt /
[root@node3 ~]# hadoop fs -cat /1.txt
1
[root@node3 ~]# hadoop fs -appendToFile 2.txt 3.txt /1.txt
[root@node3 ~]# hadoop fs -cat /1.txt
1
2
3
[root@node3 ~]# 
​
#追加的用途:把本地的小文件上传中合并成为大文件 解决小文件场景的。
6.文件内容查看 -cat
#案例查看hadoop内01.txt文件内容
hdfs dfs -cat /bai/01.txt
7.权限 拥有者 所属组修改
    hdfs在设计的时候 借鉴模仿着linux权限管理模式
    也有所谓的读写执行 user group others  777
chgrp  修改所属组
chmod  修改权限
cgown  修改拥有者
​
hadoop fs -chmod 755 /1.txt
8.移动,剪切,重命名 -mv
hdfs dfs -mv `要移动,剪切,原名字` `目标路径,新名字`
#案例 将/bai/下的01.txt文件 移动到/bai_01/下重命名02.txt
hdfs dfs -mv /bai/01.txt /bai_01/02.txt
9.复制 -cp
#将/bai/01.txt 复制到/bai_01/
hdfs dfs -cp /bai/01.txt /bai_01/
10.删除 -rm
hdfs dfs -rm -r/bai
-r 递归删除
11.合并下载 -getmerge
合并下载多个文件  其功能和appendToFile相反的动作 ```下载到Linux文件下
#案例
[root@node3 ~]# hadoop fs -mkdir /small
[root@node3 ~]# hadoop fs -put *.txt /small
[root@node3 ~]# hadoop fs -getmerge /small/* ./merge.txt
[root@node3 ~]# cat merge.txt 
12.统计HDFS可用空间 指定目录大小 -df
hadoop fs -df -h /
```Filesystem            Size   Used  Available  Use%
```hdfs://node1:8020  111.1 G  5.0 M     98.3 G    0%
13.修改文件的副本数 -setrep
hadoop fs -setrep -w N -R   N就是修改之后的副本数
-w wait等待 修改副本客户端是否等待修改完毕再退出
#案例 把1.txt文件副本数修改为2
hadoop fs -setrep 2 /small/1.txt
```Replication 2 set: /small/1.txt
​
hadoop fs -setrep -w 2 /small/2.txt
```Replication 2 set: /small/2.txt
```Waiting for /small/2.txt ...
WARNING: the waiting time may be long for DECREASING the number of replications.
. done
14.HDFS集群

地址: http://node1:9870

15.YARN集群

地址:http://resourcemanager_host:8088

16.jobhistory

地址:http://node1:19888/jobhistory

  • 26
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值