The command in Hadoop checks whether the hdfs file exists
In Hadoop, you can check the existence of a HDFS file using the following command:
hadoop fs -test -e
where is the path to the HDFS file to check.
If the file exists, the command returns 0; if the file does not exist, the command returns a non-zero value.
Here is an example:
hadoop fs -test -e /user/hadoop/myfile.txt
if [ $? -eq 0 ]; then
echo "文件存在"
# 执行相应操作...
else
echo "文件不存在"
# 执行其他操作或跳过处理...
fi
In the example, use the hadoop fs -test -e command to check whether the /user/hadoop/myfile.txt file exists. Next, the existence of the file is determined by checking the return value of the command.