hadoop常用命令

0)启动 Hadoop 集群(方便后续的测试)
[atguigu@hadoop102 hadoop-2.7.2]$ sbin/start-dfs.sh
[atguigu@hadoop103 hadoop-2.7.2]$ sbin/start-yarn.sh
(1)-help:输出这个命令参数
[atguigu@hadoop102 hadoop-2.7.2]$ hadoop fs -help rm
(2)-ls: 显示目录信息
[atguigu@hadoop102 hadoop-2.7.2]$ hadoop fs -ls /
(3)-mkdir:在 hdfs 上创建目录
[atguigu@hadoop102 hadoop-2.7.2]$ hadoop fs -mkdir -p /user/atguigu/test
(4)-moveFromLocal 从本地剪切粘贴到 hdfs
[atguigu@hadoop102 hadoop-2.7.2]$ touch jinlian.txt
[atguigu@hadoop102 hadoop-2.7.2]$ hadoop fs -moveFromLocal ./jinlian.txt
/user/atguigu/test
(5)–appendToFile :追加一个文件到已经存在的文件末尾
[atguigu@hadoop102 hadoop-2.7.2]$ touch ximen.txt
[atguigu@hadoop102 hadoop-2.7.2]$ vi ximen.txt
wo ai jinlian
[atguigu@hadoop102 hadoop-2.7.2]$ hadoop fs -appendToFile ximen.txt
/user/atguigu/test/jinlian.txt
(6)-cat :显示文件内容
(7)-tail:显示一个文件的末尾
[atguigu@hadoop102 hadoop-2.7.2]$ hadoop fs -tail /user/atguigu/test/jinlian.txt
(8)-chgrp 、-chmod、-chown:linux 文件系统中的用法一样,修改文件所属权限
[atguigu@hadoop102 hadoop-2.7.2]$ hadoop fs -chmod 666
/user/atguigu/test/jinlian.txt
[atguigu@hadoop102 hadoop-2.7.2]$ hadoop fs -chown atguigu:atguigu
/user/atguigu/test/jinlian.txt
(9)-copyFromLocal:从本地文件系统中拷贝文件到 hdfs 路径去
[atguigu@hadoop102 hadoop-2.7.2]$ hadoop fs -copyFromLocal README.txt
/user/atguigu/test
(10)-copyToLocal:从 hdfs 拷贝到本地
[atguigu@hadoop102 hadoop-2.7.2]$ hadoop fs -copyToLocal
/user/atguigu/test/jinlian.txt ./jinlian.txt
(11)-cp :从 hdfs 的一个路径拷贝到 hdfs 的另一个路径
[atguigu@hadoop102 hadoop-2.7.2]$ hadoop fs -cp /user/atguigu/test/jinlian.txt
/jinlian2.txt
(12)-mv:在 hdfs 目录中移动文件
[atguigu@hadoop102 hadoop-2.7.2]$ hadoop fs -mv /jinlian2.txt /user/atguigu/test/
(13)-get:等同于 copyToLocal,就是从 hdfs 下载文件到本地
[atguigu@hadoop102 hadoop-2.7.2]$ hadoop fs -get /user/atguigu/test/jinlian2.txt ./
(14)-getmerge :合并下载多个文件,比如 hdfs 的目录 /aaa/下有多个文件:log.1,
log.2,log.3,…
[atguigu@hadoop102 hadoop-2.7.2]$ hadoop fs -getmerge
/user/atguigu/test/* ./zaiyiqi.txt
(15)-put:等同于 copyFromLocal
[atguigu@hadoop102 hadoop-2.7.2]$ hadoop fs -put ./zaiyiqi.txt /user/atguigu/test/
(16)-rm:删除文件或文件夹
[atguigu@hadoop102 hadoop-2.7.2]$ hadoop fs -rm /user/atguigu/test/jinlian2.txt
(17)-rmdir:删除空目录
[atguigu@hadoop102 hadoop-2.7.2]$ hadoop fs -mkdir /test
[atguigu@hadoop102 hadoop-2.7.2]$ hadoop fs -rmdir /test
(18)-df :统计文件系统的可用空间信息
[atguigu@hadoop102 hadoop-2.7.2]$ hadoop fs -df -h /
(19)-du 统计文件夹的大小信息
[atguigu@hadoop102 hadoop-2.7.2]$ hadoop fs -du -s -h /user/atguigu/test
2.7 K /user/atguigu/test
[atguigu@hadoop102 hadoop-2.7.2]$ hadoop fs -du -h /user/atguigu/test
1.3 K /user/atguigu/test/README.txt
15 /user/atguigu/test/jinlian.txt
1.4 K /user/atguigu/test/zaiyiqi.txt
(20)-setrep:设置 hdfs 中文件的副本数量
[atguigu@hadoop102 hadoop-2.7.2]$ hadoop fs -setrep 2 /user/atguigu/test/jinlian.txt
这里设置的副本数只是记录在 namenode 的元数据中,是否真的会有这么多副本,还得
看 datanode 的数量。因为目前只有 3 台设备,最多也就 3 个副本,只有节点数的增加到 10
台时,副本数才能达到 10。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值