我想检查一个文件是否存在于 hdfs 中。我正在使用
if $(hadoop fs -test -e $myfilewithpath) ; then echo "ok";else echo "not ok"; fi
现在我收到类似
的错误消息test: `/data/bi/udm/incoming/Viewership/year=2016/month=02/day=26/hour=07/part-m-*.avro': No such file or directory
not ok
我在路径中期望的文件可以是任何映射器输出文件,即它可以是 part-m-00000.avro
或者它可以是 part-m-00099.avro
这就是我在搜索中使用 *
的原因,例如 part-m-*.avro
。
但是我们可以消除下面的消息并只得到输出 not ok
test: `/data/bi/udm/incoming/Viewership/year=2016/month=02/day=26/hour=07/part-m-*.avro': No such file or directory
最佳答案
我可以通过下面的代码解决它
if $(hadoop fs -ls $tilldirectorypath|grep "part-m-*.avro") ; then echo "ok";else echo "not ok"; fi
Where tilldirectorypath=/data/bi/udm/incoming/Viewership/year=2016/month=02/day=26/hour=07
And previous path defined as myfilewithpath=/data/bi/udm/incoming/Viewership/year=2016/month=02/day=26/hour=07/part-m-*.avro
关于hadoop - 使用通配符检查文件是否存在于 hdfs 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35659371/