【Hadoop】hdfs dfs -test命令
使用方法
hdfs dfs -test -[defswrz] <path> :
Answer various questions about <path>, with result via exit status.
-d return 0 if <path> is a directory.
-e return 0 if <path> exists.
-f return 0 if <path> is a file.
-s return 0 if file <path> is greater than zero bytes in size.
-w return 0 if file <path> exists and write permission is granted.
-r return 0 if file <path> exists and read permission is granted.
-z return 0 if file <path> is zero bytes in size, else return 1.
获取返回值
1. shell
$?
[示例]
[root@emr-worker-2 ~]# hadoop fs -test -e /tmp
[root@emr-worker-2 ~]# echo $?
0
[root@emr-worker-2 ~]# hadoop fs -test -e /tmp1
[root@emr-worker-2 ~]# echo $?
1
2. Java
val cmd = Array("sh", "-c", s"hdfs dfs -test -e /tmp " + " ; echo $?")
val checkDirExistsProcess = Runtime.getRuntime.exec(cmd)
val stream = checkDirExistsProcess.getInputStream
val reader = new BufferedReader(new InputStreamReader(stream))
var result = ""
var line = reader.readLine()
while (line != null) {
result += line
line = reader.readLine()
}
val exitCode = checkDirExistsProcess.waitFor()
println(s"checkDirExistsProcess exit code: $exitCode")
stream.close()
reader.close()
关于cmd为什么这样写,可以查看这篇博客 https://blog.csdn.net/Sonsay/article/details/109491248
查看方法
hdfs dfs -help
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 【译】Visual Studio 中新的强大生产力特性
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构
· 字符编码:从基础到乱码解决
2021-12-29 Markdown表情符号