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

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

jackletter

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值