hadoop中的shell命令

hadoop fs [generic options]

  1. [-appendToFile … ]
    将本地指定文件的内容,添加到HDFS中的指定文件中
    例如:$ hadoop fs -appendToFile - /1.txt
    其中 - 代表的是可以从标准输入进行追加

  2. [-cat [-ignoreCrc] …]
    查询HDFS中的文件的内容

  3. [-checksum …]
    校验和,得出

    [Lancer@hadoop106 ~]$ hadoop fs -checksum /1.txt
    /1.txt	MD5-of-0MD5-of-512CRC32C	00000200000000000000000068b2904fb9eb669ffe961cc56f69d178
    
  4. [-chgrp [-R] GROUP PATH…]
    改变的是文件的属组,但是没有办法改变属主

    $ hadoop fs -chgrp lancer /1.txt
    

    得出这样的效果
    在这里插入图片描述

  5. [-chmod [-R] <MODE[,MODE]… | OCTALMODE> PATH…]

    $ hadoop fs -chmod +x /1.txt
    

    改变的是文件的权限

  6. [-chown [-R] [OWNER][:[GROUP]] PATH…]

    $ hadoop fs -chown lancer:qamar /1.txt
    

    改变文件的属主和属组,但是如果只写一个的话,只改变文件的属主。

  7. [-copyFromLocal [-f] [-p] [-l] … ]

    $ hadoop fs -copyFromLocal 1.txt /t3
    

    把本地的文件,拷贝到HDFS中,跟put的用法是一样的。

  8. [-copyToLocal [-p] [-ignoreCrc] [-crc] … ]

    $ hadoop fs -copyToLocal /1.txt t3
    

    从HDFS中拷贝文件到本地。

  9. [-count [-q] [-h] …]

    $ hadoop fs -count /t5
     2            0                  0 /t5
    

    第一个表示文件夹的个数,第二个数字表示文件夹中文件的个数,第三个数字表示大小,

    1. [-cp [-f] [-p | -p[topax]] … ]
     ```
     $ hadoop fs -cp /1.txt  /t4
     ```
     表示在HDFS中,一个文件拷贝到另一个文件夹中拷贝
    
    1. [-df [-h] [ …]]
     ```
     $ hadoop fs -df -h /
     ```
     (linux下是查询磁盘空间大小)也可以查询某个目录的空间大小查看根目录下磁盘空间大小。注意加 -h 和不加的区别
    
    1. [-du [-s] [-h] …]
     ```
     $ hadoop fs -du /
     ```
     ![根目录结果](https://img-blog.csdnimg.cn/20181205223955984.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl80MzgzNjQzMg==,size_16,color_FFFFFF,t_70)
     统计各个目录以及各个文件的大小
     加了 -s ,表示这个整个文件夹的大小
     ![在这里插入图片描述](https://img-blog.csdnimg.cn/20181205224227372.png)
    
    1. [-get [-p] [-ignoreCrc] [-crc] … ]
     ```
     $ hadoop fs -get /111.txt ./
     ```
     表示从HDFS中拷贝文件到本地当前文件夹
    
    1. [-getfacl [-R] ]

      $ hadoop fs -getfacl /1.txt
      

      (得到访问控制的列表)可以简单理解为查看这个文件的权限以及用户使用权限的信息。
      在这里插入图片描述

    2. [-setfattr {-n name [-v value] | -x name} ]

     为某个目录设置权限
    
    1. [-getmerge [-nl] ]

      $ hadoop fs -getmerge /*.txt lan
      

      合并下载,从HDFS中的多个文件下载到本地一个文件,只支持通配符,例如*,只能是文件,不能是文件夹。

    2. [-help [cmd …]]

      得到某个命令的具体介绍

      [Lancer@hdp6 ~]$ hadoop fs -help ls
      -ls [-d] [-h] [-R] [<path> ...] :
        List the contents that match the specified file pattern. If path is not
        specified, the contents of /user/<currentUser> will be listed. Directory entries
        are of the form:
        	permissions - userId groupId sizeOfDirectory(in bytes)
        modificationDate(yyyy-MM-dd HH:mm) directoryName
        
        and file entries are of the form:
        	permissions numberOfReplicas userId groupId sizeOfFile(in bytes)
        modificationDate(yyyy-MM-dd HH:mm) fileName
                                                                                       
        -d  Directories are listed as plain files.                                     
        -h  Formats the sizes of files in a human-readable fashion rather than a number
            of bytes.                                                                  
        -R  Recursively list the contents of directories. 
      
    3. [-ls [-d] [-h] [-R] [ …]]

      该文件下的文件列表

      $ hadoop fs -ls /
      
    4. [-mkdir [-p] …]

      创建一个名为Lancer的文件夹

      $ hadoop fs -mkdir /lancer
      
    5. [-moveFromLocal … ]

      将本地文件 a 剪切到HDFS根目录中

      $ hadoop fs -moveFromLocal a /
      
    6. [-mv … ]

      在HDFS中一个文件移动到另一个位置,相当于剪切

      $ hadoop fs -mv /a /lancer
      
    7. [-put [-f] [-p] [-l] … ]

      将本地的文件复制到HDFS中

      $ hadoop fs -put lan /lancer
      

      在这里插入图片描述

    8. [-rm [-f] [-r|-R] [-skipTrash] …]

      在HDFS中删除某个文件

      [Lancer@hdp6 ~]$ hadoop fs -rm  /111.txt
      18/12/06 22:14:22 INFO fs.TrashPolicyDefault: Namenode trash configuration: Deletion interval = 0 minutes, Emptier interval = 0 minutes.
      Deleted /111.txt
      
    9. [-rmdir [–ignore-fail-on-non-empty]

      …]

     从HDFS中删除空文件夹,只能是空文件夹
     ```
     $ hadoop fs -rmdir /t5/t2
     ```
    
    1. [-setrep [-R] [-w] …]
     设置修改副本的数量,
     ![在这里插入图片描述](https://img-blog.csdnimg.cn/20181205231539225.png)
     ```
     [Lancer@hdp6 ~]$ hadoop fs -setrep 2 /1.txt
     Replication 2 set: /1.txt
     ```
     将副本数量修改为2个,
     ![在这里插入图片描述](https://img-blog.csdnimg.cn/20181205231727801.png)
    
    1. [-stat [format] …]

      默认的是创建文件的时间,format是格式,不同的格式,信息也会不一样。

      [Lancer@hdp6 ~]$ hadoop fs -stat /1.txt
      2018-12-06 13:18:17
      #注意,时间为HDFS中的时间,非实际创建的时间。
      [Lancer@hdp6 ~]$ hadoop fs -help stat
      -stat [format] <path> ... :
        Print statistics about the file/directory at <path>
        in the specified format. Format accepts filesize in
        blocks (%b), type (%F), group name of owner (%g),
        name (%n), block size (%o), replication (%r), user name
        of owner (%u), modification date (%y, %Y).
        %y shows UTC date as "yyyy-MM-dd HH:mm:ss" and
        %Y shows milliseconds since January 1, 1970 UTC.
        If the format is not specified, %y is used by default.
      
      [Lancer@hdp6 ~]$ hadoop fs -stat %g /1.txt
      qamar
      
    2. [-tail [-f] ]

     可以看文件最后十行内容,还可以实时监控。
     ```
     $ hadoop fs -tail /1.txt
     ```
     下面为监控的过程
     ```
     [Lancer@hdp6 ~]$ hadoop fs -tail -f  /1.txt
     111111111111111111111111111111111
     222222222222
     
     33333333
     4444444
     555555555555
     2222
     333
     44
     55
     
     ```
     ```
     [Lancer@hdp6 ~]$ hadoop fs -appendToFile - /1.txt
     sssss
     cccc
     dddd
     ffff
     ^C[Lancer@hdp6 ~]$ 
     ```
     ```
     [Lancer@hdp6 ~]$ hadoop fs -tail -f  /1.txt
     1111111111111111111111111111
     222222222222
     
     33333333
     4444444
     5555555555
     2222
     333
     44
     55
     sssss
     cccc
     dddd
     ffff
     ```
    
    1. [-test -[defsz] ]
     必须结合defsz来,判断文件目录是否存在,并用echo $? 查看结果
     
     ```
     [Lancer@hdp6 ~]$ hadoop fs -help test
     -test -[defsz] <path> :
       Answer various questions about <path>, with result via exit status.
         -d  return 0 if <path> is a directory.
         -e  return 0 if <path> exists.
         -f  return 0 if <path> is a file.
         -s  return 0 if file <path> is greater than zero bytes in size.
         -z  return 0 if file <path> is zero bytes in size, else return 1.
     #介绍test的功能
     ```
     
     ```
     [Lancer@hdp6 ~]$ hadoop fs -test -d  /lancer
     [Lancer@hdp6 ~]$ echo $?
     0
     #Lancer这个是文件夹么?
     #是,结果为0
     ```
    
    1. [-text [-ignoreCrc] …]
     拿到HDFS一个源文件。并输出文件中的内容
     
     ```
     -text [-ignoreCrc] <src> ... :
       Takes a source file and outputs the file in text format.
       The allowed formats are zip and TextRecordInputStream and Avro.
     ```
     ```
     [Lancer@hdp6 ~]$ hadoop fs -text /1.txt
     1111111111111
     222222222222
     
     33333333
     4444444
     5555555555555555555
     2222
     333
     44
     55
     sssss
     cccc
     dddd
     ffff
     ```
    
    1. [-touchz …]
     在HDFS上创建一个空的文件
     ```
     -touchz <path> ... :
       Creates a file of zero length at <path> with current time as the timestamp of
       that <path>. An error is returned if the file exists with non-zero length
     
     ```
    
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值