本文主要介紹 Hadoop 經常使用的命令。html
用於檢測文件或目錄是否存在,判斷文件或目錄大小。apache
-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.
用例:oop
1.判斷文件或目錄是否存在spa
hadoop fs -test -e /hive/warehouse/test/
echo $? #獲取最近一次調用的返回值 0表示存在,1表示不存在
2.判斷文件或目錄大小是否爲0code
hadoop fs -text -z /hive/warehouse/test/tmp echo $? #0表示文件或目錄大小爲0
【參考資料】htm
[1]. https://hadoop.apache.org/docs/r2.6.0/hadoop-project-dist/hadoop-common/FileSystemShell.html#text.blog