本文主要介绍 Hadoop 常用的命令。

test命令

用于检测文件或目录是否存在,判断文件或目录大小。

-test -[defsz] <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.
    -z  return 0 if file <path> is zero bytes in size.
else return 1.

用例:

1.判断文件或目录是否存在

hadoop fs -test -e /hive/warehouse/test/
echo $?  #获取最近一次调用的返回值 0表示存在,1表示不存在

2.判断文件或目录大小是否为0

hadoop fs -text -z /hive/warehouse/test/tmp
echo $?  #0表示文件或目录大小为0

 

【参考资料】

[1]. https://hadoop.apache.org/docs/r2.6.0/hadoop-project-dist/hadoop-common/FileSystemShell.html#text.

相关文章:

  • 2021-12-11
  • 2021-11-30
  • 2021-08-08
  • 2021-10-02
  • 2021-10-03
  • 2021-12-03
  • 2021-06-06
猜你喜欢
  • 2021-07-02
  • 2022-12-23
  • 2022-03-04
  • 2021-09-09
  • 2021-11-29
相关资源
相似解决方案