如果目录不存在,使用bash在HDFS中创建目录

  发布于 2022-12-31 13:36

我想测试Hadoop分布式文件系统(HDFS)中是否存在目录.我想创建目录,如果它不存在,否则什么都不做.

当我修改http://jugnu-life.blogspot.com/2012/10/hadoop-fs-test-example.html上的代码时:

#!/bin/bash
directory=/raw/tool/

if hadoop fs -test –d $directory ; then
    echo "Directory  exists"
else
    hadoop fs -mkdir $directory
    echo "Creating  directory"
fi

我收到错误:

-test: Too many arguments: expected 1 but got 2
Usage: hadoop fs [generic options] -test -[defsz] 

我究竟做错了什么?

1 个回答
  • 假设你复制/粘贴了你的例子,那么 - 在d之前是不正确的.我从你的帖子中复制了命令行,注意 - 在一天之前扩展的方式不同.

    $ echo -test | od -c
    0000000   -   t   e   s   t  \n
    
    $ echo –d | od -c
    0000000 342 200 223   d  \n
    

    2022-12-31 13:39 回答
撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有