hadoop下hdfs的shell命令

  1. 列出hadoop中当前用户的数据目录
    [root@localhost bin]# ./hdfs dfs -ls
    Found 2 items
    drwxr-xr-x - root supergroup 0 2019-01-25 15:24 input1
    drwxr-xr-x - root supergroup 0 2019-01-25 15:26 output
  2. 列出hadoop中根目录下的内容
    [root@localhost bin]# ./hdfs dfs -ls /
    Found 1 items
    drwxr-xr-x - root supergroup 0 2019-01-25 15:20 /user
  3. 列出/user目录下的内容
    [root@localhost bin]# ./hdfs dfs -ls /user
    Found 1 items
    drwxr-xr-x - root supergroup 0 2019-01-25 15:26 /user/root
  4. 列出/user/root下面的内容
    [root@localhost bin]# ./hdfs dfs -ls /user/root
    Found 2 items
    drwxr-xr-x - root supergroup 0 2019-01-25 15:24 /user/root/input1
    drwxr-xr-x - root supergroup 0 2019-01-25 15:26 /user/root/output
  5. 使用url格式访问namenode
    [root@localhost bin]# ./hdfs dfs -ls hdfs://localhost:9000/
    Found 1 items
    drwxr-xr-x - root supergroup 0 2019-01-25 15:20 hdfs://localhost:9000/user

    [root@localhost bin]# ./hdfs dfs -ls hdfs://localhost:9000/user
    Found 1 items
    drwxr-xr-x - root supergroup 0 2019-01-25 15:26 hdfs://localhost:9000/user/root
  6. 在当前用户目录下创建目录demo
    [root@localhost bin]# ./hdfs dfs -mkdir demo
    [root@localhost bin]# ./hdfs dfs -ls -R /
    drwxr-xr-x - root supergroup 0 2019-01-25 15:20 /user
    drwxr-xr-x - root supergroup 0 2019-01-29 08:58 /user/root
    drwxr-xr-x - root supergroup 0 2019-01-29 08:58 /user/root/demo
    ...
  7. 创建文件demo/test.txt
    [root@localhost bin]# ./hdfs dfs -touch demo/test.txt
    [root@localhost bin]# ./hdfs dfs -ls -R
    drwxr-xr-x - root supergroup 0 2019-01-29 09:08 demo
    -rw-r--r-- 1 root supergroup 0 2019-01-29 09:08 demo/test.txt
  8. 将本地文件test.txt拷贝到demo/d.txt文件中
    [root@localhost bin]# ./hdfs dfs -copyFromLocal test.txt demo/d.txt
  9. 查看hdfs中的文件 demo/d.txt
    [root@localhost bin]# ./hdfs dfs -cat demo/d.txt
    this is a deno
  10. 将本地文件a上传到demo/abc
    [root@localhost bin]# ./hdfs dfs -put a demo/abc
    [root@localhost bin]# ./hdfs dfs -cat demo/abc
    this is another demo,i'm xiaoming,who are you?
  11. 将hdfs上的文件移动(重命名)
    [root@localhost bin]# ./hdfs dfs -mv demo/abc demo/cde
  12. 将hdfs上的文件复制一份
    [root@localhost bin]# ./hdfs dfs -cp demo/cde demo/ok
  13. 将本地目录d上传到hdfs中
    [root@localhost bin]# ./hdfs dfs -copyFromLocal d demo/d
    [root@localhost bin]# ./hdfs dfs -ls -R demo
    -rw-r--r-- 1 root supergroup 47 2019-01-29 09:20 demo/cde
    drwxr-xr-x - root supergroup 0 2019-01-29 09:28 demo/d
    drwxr-xr-x - root supergroup 0 2019-01-29 09:28 demo/d/j
    -rw-r--r-- 1 root supergroup 5 2019-01-29 09:28 demo/d/j/y
    -rw-r--r-- 1 root supergroup 3 2019-01-29 09:28 demo/d/ok
    -rw-r--r-- 1 root supergroup 3 2019-01-29 09:28 demo/d/p
    -rw-r--r-- 1 root supergroup 15 2019-01-29 09:17 demo/d.txt
    -rw-r--r-- 1 root supergroup 47 2019-01-29 09:24 demo/ok
    -rw-r--r-- 1 root supergroup 0 2019-01-29 09:08 demo/test.txt
  14. 使用put命令将本地目录d上传到hdfs中
    [root@localhost bin]# ./hdfs dfs -put d k
    [root@localhost bin]# ./hdfs dfs -ls -R k
    drwxr-xr-x - root supergroup 0 2019-01-29 09:29 k/j
    -rw-r--r-- 1 root supergroup 5 2019-01-29 09:29 k/j/y
    -rw-r--r-- 1 root supergroup 3 2019-01-29 09:29 k/ok
    -rw-r--r-- 1 root supergroup 3 2019-01-29 09:29 k/p
  15. 将hdfs中的文件拷贝到本地
    [root@localhost bin]# ./hdfs dfs -get k dd
    [root@localhost bin]# ls dd -R
    dd:
    j ok p

    dd/j:
    y
  16. 使用copyToLocal命令将文件拷贝到本地
    [root@localhost bin]# ./hdfs dfs -copyToLocal k ddd
  17. 删除hdfs中的文件
    [root@localhost bin]# ./hdfs dfs -rm demo/cde
    Deleted demo/cde

    ./hdfs dfs -rm -r demo/cde
  18. 删除hdfs中的目录
    [root@localhost bin]# ./hdfs dfs -rm -r k
    Deleted k

猜你喜欢

转载自www.cnblogs.com/jackletter/p/10338412.html