• HDFS 常用命令


    参考链接

      http://segmentfault.com/a/1190000002672666

    1.ls

     列出hdfs文件系统根目录下的目录和文件

    hadoop@Master:~$ hadoop fs -ls  /
    Found 3 items
    drwxr-xr-x   - hadoop supergroup          0 2015-07-10 13:53 /hbase
    drwx-wx-wx   - hadoop supergroup          0 2015-07-11 17:21 /tmp
    drwxr-xr-x   - hadoop supergroup          0 2015-07-11 15:55 /user

     列出hdfs文件系统所有的目录和文件

    hadoop@Master:~$ hadoop fs -ls -R /
    drwxr-xr-x   - hadoop supergroup          0 2015-07-10 13:53 /hbase
    drwxr-xr-x   - hadoop supergroup          0 2015-07-10 13:53 /hbase/.tmp
    drwxr-xr-x   - hadoop supergroup          0 2015-07-10 13:53 /hbase/MasterProcWALs
    -rw-r--r--   4 hadoop supergroup          0 2015-07-10 13:53 /hbase/MasterProcWALs/state-00000000000000000021.log
    drwxr-xr-x   - hadoop supergroup          0 2015-07-10 13:53 /hbase/

    2.put

    hdfs file的父目录一定要存在,否则命令不会执行,其实只是上传一个文件,重名了名而已

    # hadoop fs -put < local file > < hdfs file >
    
    

    hadoop@Master:~$ hadoop fs -put 1.txt /tmp/2.txt

    # hadoop fs -put  < local file or dir >...< hdfs dir >
    hadoop@Master:~$ hadoop fs -put 1.txt /tmp/

    从键盘读取输入到hdfs file中,按Ctrl+D结束输入,hdfs file不能存在,否则命令不会执行

    #hadoop fs -put - < hdsf  file>

    hadoop@Master:~$ hadoop fs -put - /tmp/testfile
    我老家在要远的中国农村
    hadoop@Master:~$

    2.1.moveFromLocal

    与put相类似,命令执行后源文件 local src 被删除,也可以从从键盘读取输入到hdfs file中

    # hadoop fs -moveFromLocal  < local src > ... < hdfs dst >

    hadoop@Master:~$ hadoop fs -moveFromLocal 1.txt /tmp/
    moveFromLocal: `/tmp/1.txt': File exists
    hadoop@Master:~$ hadoop fs -moveFromLocal 1.txt /tmp/3.txt

    2.2.copyFromLocal

     这个和前面的moveFromLocal 不同的是复制本地文件到hdfs file,但是本地会保留源文件

    # hadoop fs -copyFromLocal  < local src > ... < hdfs dst >

    hadoop@Master:~$ hadoop fs -copyFromLocal derby.log /tmp/derby2.log
    hadoop@Master:~$ ls
    derby.log hadoop.tar.gz hbase-1.1.0.1 jdk-7u80-linux-x64.tar.gz jdk-8u45-linux-x64.tar.gz jdk1.8.0_45 metastore_db user wz
    hadoop@Master:~$

    3.get

    local file不能和 hdfs file名字不能相同,否则会提示文件已存在,没有重名的文件会复制到本地

    hadoop fs -get < hdfs file > < local file or dir>


    hadoop fs -get < hdfs file or dir > ... < local dir >
  • 相关阅读:
    详解 Python3 正则表达式(四)
    详解 Python3 正则表达式(一)
    Python之禅
    人生感悟
    详解 Python3 正则表达式(五)
    作用域与带有循环变量的默认参数相比较问题
    详解 Python3 正则表达式(三)
    python学习笔记:第三天(数字)
    python学习笔记:第四天( 字符串)
    python学习笔记:第二天(基本数据类型)
  • 原文地址:https://www.cnblogs.com/canyangfeixue/p/4639147.html
Copyright © 2020-2023  润新知