栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 前沿技术 > 云计算 > 云平台

Hadoop之hdfs操作

云平台 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Hadoop之hdfs操作

HDFS的常见Shell操作

直接在命令行中输入hdfs dfs,可以查看dfs后面可以跟的所有参数
注意:这里面的[]表示是可选项,<>表示是必填项

[root@bigdata01 hadoop-3.3.2]# hdfs dfs
Usage: hadoop fs [generic options]
        [-appendToFile  ... ]
        [-cat [-ignoreCrc]  ...]
        [-checksum [-v]  ...]
        [-chgrp [-R] GROUP PATH...]
        [-chmod [-R]  PATH...]
        [-chown [-R] [OWNER][:[GROUP]] PATH...]
        [-concat    ...]
        [-copyFromLocal [-f] [-p] [-l] [-d] [-t ] [-q ]  ... ]
        [-copyToLocal [-f] [-p] [-crc] [-ignoreCrc] [-t ] [-q ]  ... ]
        [-count [-q] [-h] [-v] [-t []] [-u] [-x] [-e] [-s]  ...]
        [-cp [-f] [-p | -p[topax]] [-d] [-t ] [-q ]  ... ]
        [-createSnapshot  []]
        [-deleteSnapshot  ]
        [-df [-h] [ ...]]
        [-du [-s] [-h] [-v] [-x]  ...]
        [-expunge [-immediate] [-fs ]]
        [-find  ...  ...]
        [-get [-f] [-p] [-crc] [-ignoreCrc] [-t ] [-q ]  ... ]
        [-getfacl [-R] ]
        [-getfattr [-R] {-n name | -d} [-e en] ]
        [-getmerge [-nl] [-skip-empty-file]  ]
        [-head ]
        [-help [cmd ...]]
        [-ls [-C] [-d] [-h] [-q] [-R] [-t] [-S] [-r] [-u] [-e] [ ...]]
        [-mkdir [-p]  ...]
        [-moveFromLocal [-f] [-p] [-l] [-d]  ... ]
        [-moveToLocal  ]
        [-mv  ... ]
        [-put [-f] [-p] [-l] [-d] [-t ] [-q ]  ... ]
        [-renameSnapshot   ]
        [-rm [-f] [-r|-R] [-skipTrash] [-safely]  ...]
        [-rmdir [--ignore-fail-on-non-empty]  ...]
        [-setfacl [-R] [{-b|-k} {-m|-x } ]|[--set  ]]
        [-setfattr {-n name [-v value] | -x name} ]
        [-setrep [-R] [-w]   ...]
        [-stat [format]  ...]
        [-tail [-f] [-s ] ]
        [-test -[defswrz] ]
        [-text [-ignoreCrc]  ...]
        [-touch [-a] [-m] [-t TIMESTAMP (yyyyMMdd:HHmmss) ] [-c]  ...]
        [-touchz  ...]
        [-truncate [-w]   ...]
        [-usage [cmd ...]]

>Generic options supported are:
-conf         specify an application configuration file
-D                define a value for a given property
-fs  specify default filesystem URL to use, overrides 'fs.defaultFS' property from configurations.
-jt   specify a ResourceManager
-files                 specify a comma-separated list of files to be copied to the map reduce cluster
-libjars                specify a comma-separated list of jar files to be included in the classpath
-archives           specify a comma-separated list of archives to be unarchived on the compute machines
>
>The general command line syntax is:
command [genericOptions] [commandOptions]
-ls:查询指定路径信息

查看hdfs根目录下的内容,默认情况下hdfs中什么都没有

[root@bigdata01 hadoop-3.3.2]#  hdfs dfs -ls hdfs://bigdata01:9000/ 
Found 23 items
-rw-r--r--   2 root  supergroup      15217 2022-04-04 16:19 hdfs://bigdata01:9000/LICENSE.txt
-rw-r--r--   3 30329 supergroup        482 2022-04-19 16:47 hdfs://bigdata01:9000/MapFile
-rw-r--r--   2 root  supergroup       1541 2022-04-04 16:19 hdfs://bigdata01:9000/NOTICE.txt
-rw-r--r--   3 30329 supergroup        482 2022-04-19 16:50 hdfs://bigdata01:9000/SeqFile
-rw-r--r--   2 root  supergroup 1860100000 2022-04-20 13:14 hdfs://bigdata01:9000/hello_10000000.dat
drwxr-xr-x   - root  supergroup          0 2022-04-10 12:14 hdfs://bigdata01:9000/log
drwxr-xr-x   - 30329 supergroup          0 2022-04-19 16:50 hdfs://bigdata01:9000/mapFile
drwxr-xr-x   - root  supergroup          0 2022-04-12 17:37 hdfs://bigdata01:9000/out
drwxr-xr-x   - root  supergroup          0 2022-04-12 17:51 hdfs://bigdata01:9000/out1
drwxr-xr-x   - root  supergroup          0 2022-04-19 17:18 hdfs://bigdata01:9000/out10
drwxr-xr-x   - root  supergroup          0 2022-04-20 16:32 hdfs://bigdata01:9000/out10000000
drwxr-xr-x   - root  supergroup          0 2022-04-19 17:28 hdfs://bigdata01:9000/out11
drwxr-xr-x   - root  supergroup          0 2022-04-19 17:30 hdfs://bigdata01:9000/out12
drwxr-xr-x   - root  supergroup          0 2022-04-12 18:05 hdfs://bigdata01:9000/out2
drwxr-xr-x   - root  supergroup          0 2022-04-13 19:31 hdfs://bigdata01:9000/out4
drwxr-xr-x   - root  supergroup          0 2022-04-13 19:51 hdfs://bigdata01:9000/out5
drwxr-xr-x   - root  supergroup          0 2022-04-13 20:03 hdfs://bigdata01:9000/out6
drwxr-xr-x   - root  supergroup          0 2022-04-28 21:25 hdfs://bigdata01:9000/outqueue
-rw-r--r--   2 root  supergroup        161 2022-04-29 08:23 hdfs://bigdata01:9000/relation.dat
drwxr-xr-x   - root  supergroup          0 2022-04-12 17:30 hdfs://bigdata01:9000/test
drwx------   - root  supergroup          0 2022-04-13 19:51 hdfs://bigdata01:9000/tmp
drwx------   - root  supergroup          0 2022-04-10 11:04 hdfs://bigdata01:9000/user
-rw-r--r--   3 30329 supergroup         13 2022-04-05 20:58 hdfs://bigdata01:9000/user1.txt

其实后面hdfs的url这一串内容在使用时默认是可以省略的,因为hdfs在执行的时候会根据HDOOP_HOME自动识别配置文件中的fs.defaultFS属性
所以这样简写也是可以的

[root@bigdata01 hadoop-3.3.2]# hdfs dfs -ls /
Found 23 items
-rw-r--r--   2 root  supergroup      15217 2022-04-04 16:19 /LICENSE.txt
-rw-r--r--   3 30329 supergroup        482 2022-04-19 16:47 /MapFile
-rw-r--r--   2 root  supergroup       1541 2022-04-04 16:19 /NOTICE.txt
-rw-r--r--   3 30329 supergroup        482 2022-04-19 16:50 /SeqFile
-rw-r--r--   2 root  supergroup 1860100000 2022-04-20 13:14 /hello_10000000.dat
drwxr-xr-x   - root  supergroup          0 2022-04-10 12:14 /log
drwxr-xr-x   - 30329 supergroup          0 2022-04-19 16:50 /mapFile
drwxr-xr-x   - root  supergroup          0 2022-04-12 17:37 /out
drwxr-xr-x   - root  supergroup          0 2022-04-12 17:51 /out1
drwxr-xr-x   - root  supergroup          0 2022-04-19 17:18 /out10
drwxr-xr-x   - root  supergroup          0 2022-04-20 16:32 /out10000000
drwxr-xr-x   - root  supergroup          0 2022-04-19 17:28 /out11
drwxr-xr-x   - root  supergroup          0 2022-04-19 17:30 /out12
drwxr-xr-x   - root  supergroup          0 2022-04-12 18:05 /out2
drwxr-xr-x   - root  supergroup          0 2022-04-13 19:31 /out4
drwxr-xr-x   - root  supergroup          0 2022-04-13 19:51 /out5
drwxr-xr-x   - root  supergroup          0 2022-04-13 20:03 /out6
drwxr-xr-x   - root  supergroup          0 2022-04-28 21:25 /outqueue
-rw-r--r--   2 root  supergroup        161 2022-04-29 08:23 /relation.dat
drwxr-xr-x   - root  supergroup          0 2022-04-12 17:30 /test
drwx------   - root  supergroup          0 2022-04-13 19:51 /tmp
drwx------   - root  supergroup          0 2022-04-10 11:04 /user
-rw-r--r--   3 30329 supergroup         13 2022-04-05 20:58 /user1.txt
-put: 从本地上传文件

接下来我们向hdfs中上传一个文件,使用Hadoop中的README.txt,直接上传到hdfs的根目录即可

[root@bigdata01 hadoop-3.3.2]# hdfs dfs -put README.txt /

上传成功之后没有任何提示,注意,没有提示就是最好的结果
确认一下刚才上传的文件

[root@bigdata01 hadoop-3.3.2]# hdfs dfs -ls /

在这里可以发现使用hdfs中的ls查询出来的信息和在linux中执行ll查询出来的信息是类似的
在这里能看到这个文件就说明刚才的上传操作是成功的

-cat: 查看HDFS文件内容

文件上传上去以后,查看一下HDFS中文件的内容,使用cat即可

[root@bigdata01 hadoop-3.3.2]# hdfs dfs -cat /README.txt
-get: 下载文件到本地

如果我们想把hdfs中的文件下载到本地linux文件系统中需要怎么做呢?使用get即可实现

[root@bigdata01 hadoop-3.3.2]# hdfs dfs -get /README.txt
-mkdir[-p]: 创建文件夹

后期我们需要在hdfs中维护很多文件,所以就需要创建文件夹来进行分类管理了
下面我们来创建一个文件夹,hdfs中使用mkdir命令

[root@bigdata01 hadoop-3.3.2]# hdfs dfs -mkdir /test

如果要递归创建多级目录,还需要再指定-p参数

[root@bigdata01 hadoop-3.3.2]# hdfs dfs -mkdir -o /abc/xyz

想要递归显示所有目录的信息,可以在ls后面添加-R参数

[root@bigdata01 hadoop-3.3.2]# hdfs dfs -ls -R /
-rm[-r]: 删除文件/文件夹

如果想要删除hdfs中的目录或者文件,可以使用rm
删除文件

[root@bigdata01 hadoop-3.3.2]# hdfs dfs -rm /README.txt

删除目录,注意,删除目录需要指定-r参数

[root@bigdata01 hadoop-3.3.2]# hdfs dfs -rm -r /abc
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/895839.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号