URLをダウンロードせずに存在することを確認したいと思います。私は以下を使用していますcurl
:
if [[ $(curl ftp://ftp.somewhere.com/bigfile.gz) ]] 2>/dev/null;
then
echo "This page exists."
else
echo "This page does not exist."
fi
または以下を使用してくださいwget
。
if [[ $(wget ftp://ftp.somewhere.com/bigfile.gz) -O-]] 2>/dev/null;
then
echo "This page exists."
else
echo "This page does not exist."
fi
URLが存在しない場合は完全に機能します。存在する場合、ファイルがダウンロードされます。私の場合、ファイルは非常に大きく、ダウンロードしたくありません。 URLが存在するかどうかを知りたいです。
ベストアンサー1
あなたは近いです。この問題を解決する正しい方法は、次を使用することです。頭方法。
カールの使用:
if curl --head --silent --fail ftp://ftp.somewhere.com/bigfile.gz 2> /dev/null;
then
echo "This page exists."
else
echo "This page does not exist."
fi
またはwgetを使用してください:
if wget -q --method=HEAD ftp://ftp.somewhere.com/bigfile.gz;
then
echo "This page exists."
else
echo "This page does not exist."
fi