美文网首页
Hadoop-Shell 命令

Hadoop-Shell 命令

作者: 夏天嘚花花 | 来源:发表于2019-03-10 23:10 被阅读0次
    hadoop fs 和 hadoop dfs 和 hdfs dfs 之间的区别

    hadoop fs : 意思是说该命令可以用于其他文件系统,不止是hdfs文件系统内,也就是说该命令的使用范围更广
    hadoop dfs : 已经弃用
    hdfs dfs : 和hadoop dfs作用相同,相比于上面的命令更为推荐,并且当使用hadoop dfs时内部会被转为hdfs dfs命令

    具体hdfs帮助命令
    [root@server-1 home]# hdfs dfs -help
    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] <localsrc> ... <dst>]
        [-copyToLocal [-p] [-ignoreCrc] [-crc] <src> ... <localdst>]
        [-count [-q] [-h] <path> ...]
        [-cp [-f] [-p | -p[topax]] <src> ... <dst>]
        [-createSnapshot <snapshotDir> [<snapshotName>]]
        [-deleteSnapshot <snapshotDir> <snapshotName>]
        [-df [-h] [<path> ...]]
        [-du [-s] [-h] <path> ...]
        [-expunge]
        [-get [-p] [-ignoreCrc] [-crc] <src> ... <localdst>]
        [-getfacl [-R] <path>]
        [-getfattr [-R] {-n name | -d} [-e en] <path>]
        [-getmerge [-nl] <src> <localdst>]
        [-help [cmd ...]]
        [-ls [-d] [-h] [-R] [<path> ...]]
        [-mkdir [-p] <path> ...]
        [-moveFromLocal <localsrc> ... <dst>]
        [-moveToLocal <src> <localdst>]
        [-mv <src> ... <dst>]
        [-put [-f] [-p] [-l] <localsrc> ... <dst>]
        [-renameSnapshot <snapshotDir> <oldName> <newName>]
        [-rm [-f] [-r|-R] [-skipTrash] <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> ...]
        [-usage [cmd ...]]
    
    
    查看hdfs文件列表
    [root@server-1 ~]# hdfs dfs -ls /
    Found 6 items
    -rw-r--r--   3 root          supergroup         78 2019-02-16 18:21 /hello.txt
    -rw-r--r--   3 root          supergroup         93 2019-02-19 05:46 /input.txt
    -rw-r--r--   3 root          supergroup  328530942 2019-02-16 18:18 /mysql-5.6.41-linux-glibc2.12-x86_64.tar.gz
    -rw-r--r--   3 Administrator supergroup       8604 2019-02-16 23:27 /nginx.conf
    -rw-r--r--   3 root          supergroup         93 2019-02-21 05:05 /wcinput
    drwxr-xr-x   - Administrator supergroup          0 2019-02-21 06:17 /wcoutput
    
    上传文件到hdfs
    [root@server-1 home]# hdfs dfs -put /home/hadoopworld.txt /
    [root@server-1 home]# hdfs dfs -ls /
    Found 7 items
    -rw-r--r--   3 root          supergroup        101 2019-03-10 07:37 /hadoopworld.txt
    -rw-r--r--   3 root          supergroup         78 2019-02-16 18:21 /hello.txt
    -rw-r--r--   3 root          supergroup         93 2019-02-19 05:46 /input.txt
    -rw-r--r--   3 root          supergroup  328530942 2019-02-16 18:18 /mysql-5.6.41-linux-glibc2.12-x86_64.tar.gz
    -rw-r--r--   3 Administrator supergroup       8604 2019-02-16 23:27 /nginx.conf
    -rw-r--r--   3 root          supergroup         93 2019-02-21 05:05 /wcinput
    drwxr-xr-x   - Administrator supergroup          0 2019-02-21 06:17 /wcoutput
    
    将hdfs上的文件下载到本地
    [root@server-1 home]# rm -rf hadoopworld.txt 
    [root@server-1 home]# hdfs dfs -get /hadoopworld.txt /home/
    [root@server-1 home]# ls
    cmake-3.2.0.tar.gz              hadoop-2.6.5.tar.gz   kafka-eagle-web-1.2.4-bin.tar.gz            src
    glibc-2.14.tar.bz2              hadoopworld.txt       mysql-5.6.39.tar.gz                         xuzy
    glibc-linuxthreads-2.5.tar.bz2  kafka_2.11-2.0.0.tgz  mysql-5.6.41-linux-glibc2.12-x86_64.tar.gz  zookeeper-3.4.12.tar.gz
    
    查看hdfs上的文件内容
    [root@server-1 home]# hdfs dfs -cat /hello.txt
    werewr
    ewtertert
    rytryrty
    werwerwe
    rtret
    
    将本地文件的文件内容以追加的方式追加到hdfs文件中
    [root@server-1 home]# echo 'xuzhiyong is a good man' > /home/xuzy.txt
    [root@server-1 home]# hdfs dfs -appendToFile xuzy.txt /hello.txt
    
    递归删除hdfs文件目录
    [root@server-1 home]# hdfs dfs -rm -r /wcoutput
    19/03/10 07:58:22 INFO fs.TrashPolicyDefault: Namenode trash configuration: Deletion interval = 0 minutes, Emptier interval = 0 minutes.
    Deleted /wcoutput
    
    在hdfs上创建一个文件
    [root@server-1 home]# hdfs dfs -touchz /xuzy.txt
    [root@server-1 home]# hdfs dfs -ls /
    Found 6 items
    -rw-r--r--   3 root          supergroup        101 2019-03-10 07:37 /hadoopworld2.txt
    -rw-r--r--   3 root          supergroup        102 2019-03-10 07:49 /hello.txt
    -rw-r--r--   3 root          supergroup         93 2019-02-19 05:46 /input.txt
    -rw-r--r--   3 root          supergroup  328530942 2019-02-16 18:18 /mysql-5.6.41-linux-glibc2.12-x86_64.tar.gz
    -rw-r--r--   3 Administrator supergroup       8604 2019-02-16 23:27 /nginx.conf
    -rw-r--r--   3 root          supergroup          0 2019-03-10 07:59 /xuzy.txt
    
    递归创建一个hdfs目录
    [root@server-1 home]# hdfs dfs -mkdir -p /xuzhiyong/01
    
    将本地的文件移到hdfs指定文件下
    [root@server-1 home]# hdfs dfs -moveFromLocal xuzy01.txt /xuzhiyong/01
    
    为hdfs指定文件或者目录赋予权限
    [root@server-1 home]# hdfs dfs -chmod -R 777 /xuzhiyong
    

    相关文章

      网友评论

          本文标题:Hadoop-Shell 命令

          本文链接:https://www.haomeiwen.com/subject/vchmpqtx.html