zoukankan      html  css  js  c++  java
  • hadoop-HDFS的Shell操作

    1.基本语法

      bin/hadoop fs 具体命令  

      bin/hdfs dfs 具体命令

    2.命令大全

    [root@master hadoop]# bin/hadoop fs
    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>            use value for 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 <comma separated list of files>    specify comma separated files to be copied to the map reduce cluster
    -libjars <comma separated list of jars>    specify comma separated jar files to include in the classpath.
    -archives <comma separated list of archives>    specify comma separated archives to be unarchived on the compute machines.
    
    The general command line syntax is
    command [genericOptions] [commandOptions]

    3.常用的命令

      3.1 -put

        将本地本地文件上传到HDFS上的/test目录下;

    hadoop fs -put 1.txt /test

          

      3.2 -mkdir

        在HDFS上创建一个文件夹,-p用于是否递归创建;

    hadoop fs -put 1.txt /wang

          

      3.3 -cat

        查看HDFS上的文件内容;

    hadoop fs -cat /test/2.txt

          

      3.4 -get

        将HDFS上的文件下载到本地;

    hadoop fs -get /test /opt/module/hadoop/

          

      3.5 -rm

        删除HDFS上的指定文件,只删除非空目录和文件;

    hadoop fs -rm /test/1.txt

          

      3.6 -getmerge

        合并下载多个文件;

    hadoop fs -getmerge /test/* merge.txt

          

         将HDFS上/test目录下的所有文件内容合并下载到本地merge.txt文件中;

      3.7 -mv

        在HDFS目录中移动文件;

    hadoop fs -mv /wang /test

          

          将HDFS上的/wang文件夹移动到/test目录下;

          注意:不允许在不同的文件系统间移动文件;

      3.8 -cp

        将HDFS的文件从原路径复制到目标路径;

    hadoop fs -cp /test/2.txt /nnn

          

      3.9 -du

        3.9.1 显示目录中所有文件的大小;

    hadoop fs -du /test

          

        3.9.2 显示文件大小;

    hadoop fs -du -s /test

          

      3.10 -touchz

        创建一个0字节的空文件;

    hadoop fs -touchz /test/www.txt

          

      3.11 -stat

        返回指定路径的统计信息;

    hadoop fs -stat /test

          

      3.12 -tail

        显示文件的末尾;

    hadoop fs -tail /test/2.txt

          

      3.13 -copyFromLocal

        将本地文件拷贝到HDFS上;

    hadoop fs -copyFromLocal merge.txt /test

          

      3.14 -moveFromLocal

        从本地文件剪切到HDFS上;  

    hadoop fs -moveFromLocal baidu.txt /test

          

         完成后,本地baidu.txt文件就删除了;

      3.15 -appendToFile

        追加一个文件到已经存在文件的末尾;

    hadoop fs -appendToFile merge.txt /test/baidu.txt

          

      3.16 -df

        统计文件夹的大小;

    hadoop fs -df -h /test

          

      3.17 -copyToLocal

        从HDFS拷贝到本地;

    hadoop fs -copyToLocal /test/baidu.txt /opt/module/hadoop/

          

  • 相关阅读:
    事务
    MySQL删除表的方式
    建立索引的原则
    对表设置引擎
    运算符
    数据库锁简介
    为什么对表设置主键
    php苹果原生apns推送接口
    华为推送
    php操作redis
  • 原文地址:https://www.cnblogs.com/wnwn/p/12532311.html
Copyright © 2011-2022 走看看