阿里云-云小站(无限量代金券发放中)
【腾讯云】云服务器、云数据库、COS、CDN、短信等热卖云产品特惠抢购

Hadoop学习:shell命令

118次阅读
没有评论

共计 4620 个字符,预计需要花费 12 分钟才能阅读完成。

Hadoop 学习:shell 命令

hdfs dfs


  • -cat URI : 查看文件内容
    1. hdfs dfs -cat hdfs dfs -cat hdfs://mycluster/user/root/rcc1
    2. hdfs dfs -cat file:///usr/hdp/2.4.2.0-258/hadoop/bin/rcc
  • -ls <args>:查文件列表
    1. 返回格式:permissions number_of_replicas userid groupid filesize modification_date modification_time filename
      [root@hdp2 ~]# hdfs dfs -ls
      Found 4 items
      drwx------   - root hdfs          0 2016-09-01 21:00 .Trash
      drwxr-xr-x   - root hdfs          0 2016-08-12 12:29 .hiveJars
      -rw-r--r--   3 root hdfs        531 2016-09-01 12:53 mapred
      -rw-r--r--   3 root hdfs       1857 2016-09-01 12:44 rcc1
  • -mkdir <paths>:创建目录
  1. The behavior is much like unix mkdir -p creating parent directories along the path
     
    [root@hdp2 ~]# hdfs dfs -ls
    Found 4 items
    drwx------   - root hdfs          0 2016-09-01 21:00 .Trash
    drwxr-xr-x   - root hdfs          0 2016-08-12 12:29 .hiveJars
    -rw-r--r--   3 root hdfs        531 2016-09-01 12:53 mapred
    -rw-r--r--   3 root hdfs       1857 2016-09-01 12:44 rcc1
    [root@hdp2 ~]# hdfs dfs -mkdir hdfs://mycluster/user/root/zhu
    [root@hdp2 ~]# hdfs dfs -ls
    Found 5 items
    drwx------   - root hdfs          0 2016-09-01 21:00 .Trash
    drwxr-xr-x   - root hdfs          0 2016-08-12 12:29 .hiveJars
    -rw-r--r--   3 root hdfs        531 2016-09-01 12:53 mapred
    -rw-r--r--   3 root hdfs       1857 2016-09-01 12:44 rcc1
    drwxr-xr-x   - root hdfs          0 2016-09-02 04:35 zhu
    Hadoop 学习:shell 命令
  • -copyFromLocal <localsrc> URI:上传文件,类似于 put
  • -put <localsrc> … <dst>
  • Hadoop 学习:shell 命令
    [root@hdp2 ~]# hdfs dfs -ls /user/root/zhu
    [root@hdp2 ~]# hdfs dfs -put /usr/zhu/a1.png /user/root/zhu
    [root@hdp2 ~]# hdfs dfs -copyFormLocal /usr/zhu/a2.png /user/root/zhu
    -copyFormLocal: Unknown command
    [root@hdp2 ~]# hdfs dfs -copyFromLocal /usr/zhu/a2.png /user/root/zhu
    [root@hdp2 ~]# hdfs dfs -ls /user/root/zhu
    Found 2 items
    -rw-r--r--   3 root hdfs      86908 2016-09-02 04:48 /user/root/zhu/a1.png
    -rw-r--r--   3 root hdfs      55823 2016-09-02 04:49 /user/root/zhu/a2.png
    [root@hdp2 ~]# 
    • -copyToLocal [-ignorecrc] [-crc] URI <localdst> : 下载到本地
    • -get [-ignorecrc] [-crc] <src> <localdst>
       
      [root@hdp2 ~]# clear
      [root@hdp2 ~]# hdfs dfs -ls /user/root/zhu
      Found 2 items
      -rw-r--r--   3 root hdfs      86908 2016-09-02 04:48 /user/root/zhu/a1.png
      -rw-r--r--   3 root hdfs      55823 2016-09-02 04:49 /user/root/zhu/a2.png
      [root@hdp2 ~]# hdfs dfs -copyToLocal hdfs://mycluster/user/root/zhu/a1.png /usr/zhu/tmp
      [root@hdp2 ~]# hdfs dfs -get /usr/root/zhu/a2.png /usr/zhu/tmp
      get: `/usr/root/zhu/a2.png': No such file or directory
      [root@hdp2 ~]# hdfs dfs -get /user/root/zhu/a2.png /usr/zhu/tmp
      [root@hdp2 ~]# cd /usr/zhu/tmp
      [root@hdp2 tmp]# ll
      total 144
      -rw-r--r-- 1 root root 86908 Sep  2 04:54 a1.png
      -rw-r--r-- 1 root root 55823 Sep  2 04:55 a2.png
      [root@hdp2 tmp]# 
      1.  

    • -count [-q] <paths> : 统计
    1. The output columns with -count are: DIR_COUNT, FILE_COUNT, CONTENT_SIZE FILE_NAME
    2. The output columns with -q are: QUOTA, REMAINING_QUATA, SPACE_QUOTA, REMAINING_SPACE_QUOTA
      [root@hdp2 tmp]# hdfs dfs -count /user/root/zhu
                 1            2             142731 /user/root/zhu
      [root@hdp2 tmp]# hdfs dfs -count -q /user/root/zhu
              none             inf            none             inf            1            2             142731 /user/root/zhu
      [root@hdp2 tmp]# 
    3.  

  • -du [-s] [-h] URI [URI …]:  统计大小
      1. The -s option will result in an aggregate summary of file lengths being displayed, rather than the individual file
      2. The -h option will format file sizes in a “human-readable” fashion (e.g 64.0m instead of 67108864)
        [root@hdp2 tmp]# hdfs dfs -du -h /user/root/zhu
        84.9 K  /user/root/zhu/a1.png
        54.5 K  /user/root/zhu/a2.png
        [root@hdp2 tmp]# 
    • -rm -r [-skipTrash] URI [URI …]
      1. -r: Recursive version of delete
         
        [root@hdp2 tmp]# hdfs dfs -ls /user/root/zhu
        Found 1 items
        -rw-r--r--   3 root hdfs      86908 2016-09-02 05:03 /user/root/zhu/a1.png
        [root@hdp2 tmp]# hdfs dfs -rm -r /user/root/zhu
        16/09/02 05:04:29 INFO fs.TrashPolicyDefault: Namenode trash configuration: Deletion interval = 360 minutes, Emptier interval = 0 minutes.
        Moved: 'hdfs://mycluster/user/root/zhu' to trash at: hdfs://mycluster/user/root/.Trash/Current
        [root@hdp2 tmp]# hdfs dfs -ls /user/root/zhu
        ls: `/user/root/zhu': No such file or directory
        [root@hdp2 tmp]# 
    • -touchz URI [URI …]
      1. Create a file of zero length
        [root@hdp2 tmp]# hdfs dfs -ls
        Found 4 items
        drwx------   - root hdfs          0 2016-09-02 05:02 .Trash
        drwxr-xr-x   - root hdfs          0 2016-08-12 12:29 .hiveJars
        -rw-r--r--   3 root hdfs        531 2016-09-01 12:53 mapred
        -rw-r--r--   3 root hdfs       1857 2016-09-01 12:44 rcc1
        [root@hdp2 tmp]# hdfs dfs -touchz a.txt
        [root@hdp2 tmp]# hdfs dfs -ls
        Found 5 items
        drwx------   - root hdfs          0 2016-09-02 05:02 .Trash
        drwxr-xr-x   - root hdfs          0 2016-08-12 12:29 .hiveJars
        -rw-r--r--   3 root hdfs          0 2016-09-02 05:08 a.txt
        -rw-r--r--   3 root hdfs        531 2016-09-01 12:53 mapred
        -rw-r--r--   3 root hdfs       1857 2016-09-01 12:44 rcc1
        [root@hdp2 tmp]# hdfs dfs -cat /user/root/a.txt
        [root@hdp2 tmp]# 
    • 小结:

    •  本质就是 Linux 文件操作命令

    下面关于 Hadoop 的文章您也可能喜欢,不妨看看:

    Ubuntu14.04 下 Hadoop2.4.1 单机 / 伪分布式安装配置教程  http://www.linuxidc.com/Linux/2015-02/113487.htm

    CentOS 安装和配置 Hadoop2.2.0  http://www.linuxidc.com/Linux/2014-01/94685.htm

    Ubuntu 13.04 上搭建 Hadoop 环境 http://www.linuxidc.com/Linux/2013-06/86106.htm

    Ubuntu 12.10 +Hadoop 1.2.1 版本集群配置 http://www.linuxidc.com/Linux/2013-09/90600.htm

    Ubuntu 上搭建 Hadoop 环境(单机模式 + 伪分布模式)http://www.linuxidc.com/Linux/2013-01/77681.htm

    Ubuntu 下 Hadoop 环境的配置 http://www.linuxidc.com/Linux/2012-11/74539.htm

    单机版搭建 Hadoop 环境图文教程详解 http://www.linuxidc.com/Linux/2012-02/53927.htm

    更多 Hadoop 相关信息见Hadoop 专题页面 http://www.linuxidc.com/topicnews.aspx?tid=13

    本文永久更新链接地址:http://www.linuxidc.com/Linux/2016-09/134887.htm

    正文完
    星哥说事-微信公众号
    post-qrcode
     0
    星锅
    版权声明:本站原创文章,由 星锅 于2022-01-21发表,共计4620字。
    转载说明:除特殊说明外本站文章皆由CC-4.0协议发布,转载请注明出处。
    【腾讯云】推广者专属福利,新客户无门槛领取总价值高达2860元代金券,每种代金券限量500张,先到先得。
    阿里云-最新活动爆款每日限量供应
    评论(没有评论)
    验证码
    【腾讯云】云服务器、云数据库、COS、CDN、短信等云产品特惠热卖中