hadoop中fs常用命令有哪些

这篇文章主要为大家展示了“hadoop中fs常用命令有哪些”,内容简而易懂,条理清晰,希望能够帮助大家解决疑惑,下面让小编带领大家一起研究并学习一下“hadoop中fs常用命令有哪些”这篇文章吧。

十余年的高州网站建设经验,针对设计、前端、开发、售后、文案、推广等六对一服务,响应快,48小时及时工作处理。成都全网营销推广的优势是能够根据用户设备显示端的尺寸不同,自动调整高州建站的显示方式,使网站能够适用不同显示终端,在浏览器中调整网站的宽度,无论在任何一种浏览器上浏览网站,都能展现优雅布局与设计,从而大程度地提升浏览体验。创新互联公司从事“高州网站设计”,“高州网站推广”以来,每个客户项目都认真落实执行。

1  介绍
      Hadoop文件系统(FS)默认提供了各种shell命令,可用于与Hadoop分布式文件系统(HDFS)或任何其他使用Hadoop Shell的支持文件系统进行交互。 一些最常用的命令是用于诸如创建目录,复制文件,查看文件内容,更改文件的所有权或权限等操作。
    hadoop fs等同于 hdfs dfs 
    [hadoop@hadoop002 hadoop]$ hdfs dfs
    Usage: hadoop fs [generic options]

2  公用命令
    2.1 创建目录命令: hdfs  dfs -mkdir
        [hadoop@hadoop002 hadoop]$ hdfs dfs -mkdir /20180523
        [hadoop@hadoop002 hadoop]$

    2.2.列出目录的内容命令: hdfs  dfs -ls
        [hadoop@hadoop002 hadoop]$ hdfs dfs -ls /
        Found 5 items
        drwxr-xr-x   - hadoop supergroup          0 2018-05-23 14:48 /20180523
        -rw-r--r--   1 hadoop supergroup         25 2018-05-23 13:04 /gw_test.log3
        drwxr-xr-x   - root   root                0 2018-05-23 13:16 /root
        drwx------   - hadoop supergroup          0 2018-05-22 11:23 /tmp
        drwxr-xr-x   - hadoop supergroup          0 2018-05-22 11:22 /user
        [hadoop@hadoop002 hadoop]$

    2.3  在HDFS中上传文件: hdfs  dfs -put ...
        [hadoop@hadoop002 hadoop]$ cd ~
        [hadoop@hadoop002 ~]$ ll
        total 4
        -rw-rw-r--. 1 hadoop hadoop  0 May 21 17:09 authorized_key
        -rw-r--r--. 1 hadoop hadoop 25 May 23 12:17 gw_test.log3
        [hadoop@hadoop002 ~]$ hdfs dfs -put gw_test.log3  /gw_test.log4

        [hadoop@hadoop002 ~]$ hdfs dfs -ls /
        Found 6 items
        drwxr-xr-x   - hadoop supergroup          0 2018-05-23 14:48 /20180523
        -rw-r--r--   1 hadoop supergroup         25 2018-05-23 13:04 /gw_test.log3
        -rw-r--r--   1 hadoop supergroup         25 2018-05-23 14:50 /gw_test.log4
        drwxr-xr-x   - root   root                0 2018-05-23 13:16 /root
        drwx------   - hadoop supergroup          0 2018-05-22 11:23 /tmp
        drwxr-xr-x   - hadoop supergroup          0 2018-05-22 11:22 /user

    2.4 从HDFS下载文件:hdfs  dfs -get
        [hadoop@hadoop002 ~]$ ll
        total 4
        -rw-rw-r--. 1 hadoop hadoop  0 May 21 17:09 authorized_key
        -rw-r--r--. 1 hadoop hadoop 25 May 23 12:17 gw_test.log3
        [hadoop@hadoop002 ~]$ hdfs dfs -get /gw_test.log4 
        [hadoop@hadoop002 ~]$ ll
        total 8
        -rw-rw-r--. 1 hadoop hadoop  0 May 21 17:09 authorized_key
        -rw-r--r--. 1 hadoop hadoop 25 May 23 12:17 gw_test.log3
        -rw-r--r--. 1 hadoop hadoop 25 May 23 14:52 gw_test.log4

    2.5 查看文件内容:hdfs  dfs -cat
        [hadoop@hadoop002 ~]$ hdfs dfs -cat /gw_test.log4 
        1111
        2222
        3333
        4444
        5555
        [hadoop@hadoop002 ~]$ 

    2.6 复制文件命令:hdfs  dfs -cp ...  
       [hadoop@hadoop002 ~]$ hdfs dfs -cp /gw_test.log3  /20180523

        [hadoop@hadoop002 ~]$ hdfs dfs -ls /20180523
        Found 1 items
        -rw-r--r--   1 hadoop supergroup         25 2018-05-23 14:55 /20180523/gw_test.log3
        [hadoop@hadoop002 ~]$ 


    2.7 将文件从源移动到目标命令: hdfs  dfs -mv
        [hadoop@hadoop002 ~]$ hdfs dfs -ls /
        Found 6 items
        drwxr-xr-x   - hadoop supergroup          0 2018-05-23 14:55 /20180523
        -rw-r--r--   1 hadoop supergroup         25 2018-05-23 13:04 /gw_test.log3
        -rw-r--r--   1 hadoop supergroup         25 2018-05-23 14:50 /gw_test.log4
        drwxr-xr-x   - root   root                0 2018-05-23 13:16 /root
        drwx------   - hadoop supergroup          0 2018-05-22 11:23 /tmp
        drwxr-xr-x   - hadoop supergroup          0 2018-05-22 11:22 /user
        [hadoop@hadoop002 ~]$ hdfs dfs -mv  /gw_test.log4  /20180523
        [hadoop@hadoop002 ~]$ hdfs dfs -ls /
        Found 5 items
        drwxr-xr-x   - hadoop supergroup          0 2018-05-23 14:57 /20180523
        -rw-r--r--   1 hadoop supergroup         25 2018-05-23 13:04 /gw_test.log3
        drwxr-xr-x   - root   root                0 2018-05-23 13:16 /root
        drwx------   - hadoop supergroup          0 2018-05-22 11:23 /tmp
        drwxr-xr-x   - hadoop supergroup          0 2018-05-22 11:22 /user
        [hadoop@hadoop002 ~]$ hdfs dfs -ls /20180523
        Found 2 items
        -rw-r--r--   1 hadoop supergroup         25 2018-05-23 14:55 /20180523/gw_test.log3
        -rw-r--r--   1 hadoop supergroup         25 2018-05-23 14:50 /20180523/gw_test.log4
        [hadoop@hadoop002 ~]$ 

        [hadoop@hadoop002 ~]$ hdfs dfs -rm -r  /20180523
        Deleted /20180523

        [hadoop@hadoop002 ~]$ hdfs dfs -ls /
        Found 4 items
        -rw-r--r--   1 hadoop supergroup         25 2018-05-23 13:04 /gw_test.log3
        drwxr-xr-x   - root   root                0 2018-05-23 13:16 /root
        drwx------   - hadoop supergroup          0 2018-05-22 11:23 /tmp
        drwxr-xr-x   - hadoop supergroup          0 2018-05-22 11:22 /user
        [hadoop@hadoop002 ~]$ 

    2.8 从HDFS中删除文件或目录命令:
        hdfs  dfs -rm        -- 删除文件
        hdfs  dfs -rm -r    -- 删除目录 
        [hadoop@hadoop002 ~]$ hdfs dfs -ls /20180523
        Found 2 items
        -rw-r--r--   1 hadoop supergroup         25 2018-05-23 14:55 /20180523/gw_test.log3
        -rw-r--r--   1 hadoop supergroup         25 2018-05-23 14:50 /20180523/gw_test.log4
        [hadoop@hadoop002 ~]$ hdfs dfs -rm /20180523/gw_test.log3
        Deleted /20180523/gw_test.log3
        [hadoop@hadoop002 ~]$ hdfs dfs -ls /20180523
        Found 1 items
        -rw-r--r--   1 hadoop supergroup         25 2018-05-23 14:50 /20180523/gw_test.log4
        [hadoop@hadoop002 ~]$ 

    2.9 显示文件的尾部命令:hdfs  dfs -tail  
        [hadoop@hadoop002 ~]$ hdfs dfs -tail  /gw_test.log3
        1111
        2222
        3333
        4444
        5555
        [hadoop@hadoop002 ~]$ 

    2.10 显示特定文件的总长度命令: hdfs  dfs -du
        [hadoop@hadoop002 ~]$ hdfs dfs -du  /gw_test.log3
        25  /gw_test.log3
        [hadoop@hadoop002 ~]$ 

    2.11 计数目录和文件命令: hdfs  dfs -count
        [hadoop@hadoop002 ~]$ hdfs dfs -count  /gw_test.log3
                   0            1                 25 /gw_test.log3

    2.12 文件系统中的空间的详细信息命名: hdfs  dfs -df  
        [hadoop@hadoop002 ~]$ hdfs dfs -df /
        Filesystem                    Size    Used    Available  Use%
        hdfs://hadoop002:9000  40028807168  704512  30802395136    0%
        [hadoop@hadoop002 ~]$ 

以上是“hadoop中fs常用命令有哪些”这篇文章的所有内容,感谢各位的阅读!相信大家都有了一定的了解,希望分享的内容对大家有所帮助,如果还想学习更多知识,欢迎关注创新互联行业资讯频道!


本文题目:hadoop中fs常用命令有哪些
本文网址:http://scyanting.com/article/popdsg.html