HDFS的Shell操作(二)

1.基本语法

bin/hdfs dfs 具体命令

2.命令大全

[root@hadoop101 hadoop]$ bin/hdfs dfs

[-appendToFile <localsrc> ... <dst>]
 [-cat [-ignoreCrc] <src> ...]
 [-checksum <src> ...]
 [-chgrp [-R] GROUP PATH...]
 [-chmod [-R] <MODE[,MODE]... | OCTALMODE> PATH...]
 [-chown [-R] [OWNER][:[GROUP]] PATH...]
 [-copyFromLocal [-f] [-p] <localsrc> ... <dst>]
 [-copyToLocal [-p] [-ignoreCrc] [-crc] <src> ... 
<localdst>]
 [-count [-q] <path> ...]
 [-cp [-f] [-p] <src> ... <dst>]
 [-createSnapshot <snapshotDir> [<snapshotName>]]
 [-deleteSnapshot <snapshotDir> <snapshotName>]
 [-df [-h] [<path> ...]]
 [-du [-s] [-h] <path> ...]
 [-expunge]
 [-get [-p] [-ignoreCrc] [-crc] <src> ... <localdst>]
 [-getfacl [-R] <path>]
 [-getmerge [-nl] <src> <localdst>]
 [-help [cmd ...]]
 [-ls [-d] [-h] [-R] [<path> ...]]
 [-mkdir [-p] <path> ...]
 [-moveFromLocal <localsrc> ... <dst>]
 [-moveToLocal <src> <localdst>]
 [-mv <src> ... <dst>]
 [-put [-f] [-p] <localsrc> ... <dst>]
 [-renameSnapshot <snapshotDir> <oldName> <newName>]
 [-rm [-f] [-r|-R] [-skipTrash] <src> ...]
 [-rmdir [--ignore-fail-on-non-empty] <dir> ...]
 [-setfacl [-R] [{-b|-k} {-m|-x <acl_spec>} <path>]|[--set 
<acl_spec> <path>]]
 [-setrep [-R] [-w] <rep> <path> ...]
 [-stat [format] <path> ...]
 [-tail [-f] <file>]
 [-test -[defsz] <path>]
 [-text [-ignoreCrc] <src> ...]
 [-touchz <path> ...]
 [-usage [cmd ...]]

3.常用命令

(1)启动 Hadoop 集群(方便后续的测试)
[root@hadoop101 hadoop]$ sbin/start-dfs.sh
[hadoop@hadoop103 hadoop]$ sbin/start-yarn.sh
(2)-help:输出这个命令参数
[root@hadoop101 hadoop]$ hdfs dfs -help rm
(3)-ls: 显示目录信息
[root@hadoop101 hadoop]$ hdfs dfs -ls /
(4)-mkdir:在 hdfs 上创建目录,-p 创建多级目录
[root@hadoop101 hadoop]$ hdfs dfs -mkdir -p /kgc/test
(5)-moveFromLocal 从本地剪切粘贴到 hdfs
[root@hadoop101 hadoop]$ touch hello.txt
[root@hadoop101 hadoop]$ hdfs dfs -moveFromLocal ./hello.txt 
/kgc/test
(6)--appendToFile :追加一个文件到已经存在的文件末尾
[root@hadoop101 hadoop]$ touch test1.txt
[root@hadoop101 hadoop]$ vi test1.txt
输入:
hadoop spark
flink spark
[root@hadoop101 hadoop]$ hdfs dfs -appendToFile test1.txt 
/kgc/test/hello.txt
(7)-cat :显示文件内容
[root@hadoop101 hadoop]$ hdfs dfs -cat /kgc/test/hello.txt
(8)-tail:显示一个文件的末尾
[root@hadoop101 hadoop]$ hdfs dfs -tail /kgc/test/hello.txt
(9)-chgrp 、-chmod、-chown:linux 文件系统中的用法一样,修改文件
所属权限
[root@hadoop101 hadoop]$ hdfs dfs -chmod 666 /kgc/test/hello.txt
[root@hadoop101 hadoop]$ hdfs dfs -chown kgc:kgc 
/kgc/test/hello.txt
(10)-copyFromLocal:从本地文件系统中拷贝文件到 hdfs 路径去
[root@hadoop101 hadoop]$ hdfs dfs -copyFromLocal README.txt /
(11)-copyToLocal:从 hdfs 拷贝到本地
[root@hadoop101 hadoop]$ hdfs dfs -copyToLocal 
/kgc/test/hello.txt ./
(12)-cp :从 hdfs 的一个路径拷贝到 hdfs 的另一个路径
[root@hadoop101 hadoop]$ hdfs dfs -cp /kgc/test/hello.txt 
/hello1.txt
(13)-mv:在 hdfs 目录中移动文件
[root@hadoop101 hadoop]$ hdfs dfs -mv /hello1.txt /kgc/test/
(14)-get:等同于 copyToLocal,就是从 hdfs 下载文件到本地
[root@hadoop101 hadoop]$ hdfs dfs -get /kgc/test/hello.txt ./
(15)-getmerge :合并下载多个文件,比如 hdfs 的目录/user/kgc/test/
下有多个文件:log.1, log.2,log.3,...,需要预先创建出目录,并存多个文件。
[root@hadoop101 hadoop]$ hdfs dfs -getmerge 
/user/kgc/test/* ./merge.txt
(16)-put:等同于 copyFromLocal
[root@hadoop101 hadoop]$ hdfs dfs -put ./merge.txt /user/kgc/test/
(17)-rm:删除文件或文件夹
[root@hadoop101 hadoop]$ hdfs dfs -rm /user/kgc/test/merge.txt
(18)-rmdir:删除空目录
[root@hadoop101 hadoop]$ hdfs dfs -mkdir /test
[root@hadoop101 hadoop]$ hdfs dfs -rmdir /test
(19)-du 统计文件夹的大小信息
[root@hadoop101 hadoop]$ hdfs dfs -du -s -h /user/kgc/test
[root@hadoop101 hadoop]$ hdfs dfs -du -h /user/kgc/test
(20)-setrep:设置 hdfs 中文件的副本数量
[root@hadoop101 hadoop]$ hdfs dfs -setrep 10 /kgc/test/hello.txt

这里设置的副本数只是记录在 NameNode 的元数据中,是否真的会有这么多副本,还得看 DataNode 的数量。如果只有 3 台设备,最多也就 3 个副本,只有节点数的增加到 10 台时,副本数才能达到 10。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值