|NO.Z.00017|——————————|BigDataEnd|——|Hadoop&HDFS.V02|——|Hadoop.v02|HDFS之shell命令行客户端|

一、HDFS之shell命令行客户端:Shell命令行操作HDFS
### --- 基本语法

~~~     bin/hadoop fs 具体命令 OR bin/hdfs dfs 具体命令
### --- 命令大全

[root@linux121 hadoop-2.9.2]# bin/hdfs dfs
Usage: hadoop fs [generic options]
    [-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] [-l] [-d] <localsrc> ... <dst>]
    [-copyToLocal [-f] [-p] [-ignoreCrc] [-crc] <src> ... <localdst>]
    [-count [-q] [-h] [-v] [-t [<storage type>]] [-u] [-x] <path> ...]
    [-cp [-f] [-p | -p[topax]] [-d] <src> ... <dst>]
    [-createSnapshot <snapshotDir> [<snapshotName>]]
    [-deleteSnapshot <snapshotDir> <snapshotName>]
    [-df [-h] [<path> ...]]
    [-du [-s] [-h] [-x] <path> ...]
    [-expunge]
    [-find <path> ... <expression> ...]
    [-get [-f] [-p] [-ignoreCrc] [-crc] <src> ... <localdst>]
    [-getfacl [-R] <path>]
    [-getfattr [-R] {-n name | -d} [-e en] <path>]
    [-getmerge [-nl] [-skip-empty-file] <src> <localdst>]
    [-help [cmd ...]]
    [-ls [-C] [-d] [-h] [-q] [-R] [-t] [-S] [-r] [-u] [<path> ...]]
    [-mkdir [-p] <path> ...]
    [-moveFromLocal <localsrc> ... <dst>]
    [-moveToLocal <src> <localdst>]
    [-mv <src> ... <dst>]
    [-put [-f] [-p] [-l] [-d] <localsrc> ... <dst>]
    [-renameSnapshot <snapshotDir> <oldName> <newName>]
    [-rm [-f] [-r|-R] [-skipTrash] [-safely] <src> ...]
    [-rmdir [--ignore-fail-on-non-empty] <dir> ...]
    [-setfacl [-R] [{-b|-k} {-m|-x <acl_spec>} <path>]|[--set <acl_spec> <path>]]
    [-setfattr {-n name [-v value] | -x name} <path>]
    [-setrep [-R] [-w] <rep> <path> ...]
    [-stat [format] <path> ...]
    [-tail [-f] <file>]
    [-test -[defsz] <path>]
    [-text [-ignoreCrc] <src> ...]
    [-touchz <path> ...]
    [-truncate [-w] <length> <path> ...]
    [-usage [cmd ...]]

Generic options supported are:
-conf <configuration file>        specify an application configuration file
-D <property=value>               define a value for a given property
-fs <file:///|hdfs://namenode:port> specify default filesystem URL to use, overrides 'fs.defaultFS' property from configurations.
-jt <local|resourcemanager:port>  specify a ResourceManager
-files <file1,...>                specify a comma-separated list of files to be copied to the map reduce cluster
-libjars <jar1,...>               specify a comma-separated list of jar files to be included in the classpath
-archives <archive1,...>          specify a comma-separated list of archives to be unarchived on the compute machines

The general command line syntax is:
command [genericOptions] [commandOptions]
二、HDFS命令演示
### --- 启动Hadoop集群(方便后续的测试)

[root@linux121 hadoop-2.9.2]# sbin/start-dfs.sh
[root@linux122 hadoop-2.9.2]# sbin/start-yarn.sh
### --- -help:输出这个命令参数

[root@linux121 ~]#  hadoop fs -help rm
### --- -ls: 显示目录信息

[root@linux121 ~]#  hadoop fs -ls /
Found 4 items
drwxr-xr-x   - root supergroup          0 2021-08-08 19:40 /test
drwx------   - root supergroup          0 2021-08-08 21:02 /tmp
drwxr-xr-x   - root supergroup          0 2021-08-08 19:46 /wcinput
drwxr-xr-x   - root supergroup          0 2021-08-08 21:36 /wcoutput
### --- -mkdir:在HDFS上创建目录

[root@linux121 ~]#  hadoop fs -mkdir -p /yanqi/bigdata
### --- -moveFromLocal:从本地剪切粘贴到HDFS

[root@linux121 ~]#  touch hadoop.txt
[root@linux121 ~]#  hadoop fs -moveFromLocal ./hadoop.txt /yanqi/bigdata
### --- -appendToFile:追加一个文件到已经存在的文件末尾

[root@linux121 ~]#  touch hdfs.txt
[root@linux121 ~]#  vim hdfs.txt
namenode datanode block replication
[root@linux121 ~]# hadoop fs -appendToFile hdfs.txt /yanqi/bigdata/hadoop.txt
### --- -cat:显示文件内容

[root@linux121 ~]# hadoop fs -cat /yanqi/bigdata/hadoop.txt
namenode datanode block replication
### --- -chgrp 、-chmod、-chown:Linux文件系统中的用法一样,修改文件所属权限

[root@linux121 ~]# hadoop fs -chmod 666 /yanqi/bigdata/hadoop.txt
[root@linux121 ~]# hadoop fs -chown root:root /yanqi/bigdata/hadoop.txt
### --- -copyFromLocal:从本地文件系统中拷贝文件到HDFS路径去

[root@linux121 ~]# hadoop fs -copyFromLocal README.txt /
### --- -copyToLocal:从HDFS拷贝到本地

[root@linux121 ~]# hadoop fs -copyToLocal /yanqi/bigdata/hadoop.txt ./
[root@linux121 ~]# ls | grep hadoop.txt 
hadoop.txt
### --- -cp :从HDFS的一个路径拷贝到HDFS的另一个路径

[root@linux121 ~]# hadoop fs -cp /yanqi/bigdata/hadoop.txt /hdfs.txt
### --- -mv:在HDFS目录中移动文件

[root@linux121 ~]# hadoop fs -mv /hdfs.txt /yanqi/bigdata/
### --- -get:等同于copyToLocal,就是从HDFS下载文件到本地

[root@linux121 ~]# hadoop fs -get /yanqi/bigdata/hadoop.txt ./
[root@linux121 ~]# ls | grep hadoop.txt 
hadoop.txt
### --- -put:等同于copyFromLocal

[root@linux121 ~]# hadoop fs -mkdir -p /user/root/test/
### --- 本地文件系统创建yarn.txt

[root@linux121 ~]# vim yarn.txt
resourcemanager nodemanager
[root@linux121 ~]#  hadoop fs -put ./yarn.txt /user/root/test/
### --- -tail:显示一个文件的末尾

[root@linux121 ~]# hadoop fs -tail /user/root/test/yarn.txt
resourcemanager nodemanager
### --- -rm:删除文件或文件夹

[root@linux121 ~]# hadoop fs -rm /user/root/test/yarn.txt
Deleted /user/root/test/yarn.txt
### --- -rmdir:删除空目录

[root@linux121 ~]# hadoop fs -mkdir /test
### --- -du统计文件夹的大小信息

[root@linux121 ~]# hadoop fs -du -s -h /user/root/test
0  /user/root/test
[root@linux121 ~]# hadoop fs -du -h /user/root/test
### --- -setrep:设置HDFS中文件的副本数量

[root@linux121 ~]#  hadoop fs -setrep 10 /yanqi/bigdata/hadoop.txt
二、图3-3 HDFS副本数量
### --- 图3-3 HDFS副本数量

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

 
 
 
 
 
 
 
 
 

Walter Savage Landor:strove with none,for none was worth my strife.Nature I loved and, next to Nature, Art:I warm'd both hands before the fire of life.It sinks, and I am ready to depart
                                                                                                                                                   ——W.S.Landor

 

posted on   yanqi_vip  阅读(24)  评论(0编辑  收藏  举报

相关博文:
阅读排行:
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 别再用vector<bool>了!Google高级工程师:这可能是STL最大的设计失误
· 单元测试从入门到精通
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

导航

统计

点击右上角即可分享
微信分享提示