
2000を超えるファイルを含むフォルダがあり、フォルダに複数のファイルがありません。
ファイル名は次のとおりです。
GLDAS_NOAH025SUBP_3H.A2003001.0000.001.2015210044609.pss.grb GLDAS_NOAH025SUBP_3H.A2003001.0600.001.2015210044609.pss.grb GLDAS_NOAH025SUBP_3H.A2003001.1200.001.2015210044609.pss.grb GLDAS_NOAH025SUBP_3H.A2003001.1800.001.2015210044609.pss.grb GLDAS_NOAH025SUBP_3H.A2003002.0000.001.2015210044609.pss.grb GLDAS_NOAH025SUBP_3H.A2003002.0600.001.2015210044609.pss.grb GLDAS_NOAH025SUBP_3H.A2003002.1200.001.2015210044609.pss.grb GLDAS_NOAH025SUBP_3H.A2003002.1800.001.2015210044609.pss.grb GLDAS_NOAH025SUBP_3H.A2003003.0000.001.2015210044609.pss.grb GLDAS_NOAH025SUBP_3H.A2003003.0600.001.2015210044609.pss.grb GLDAS_NOAH025SUBP_3H.A2003003.1200.001.2015210044609.pss.grb GLDAS_NOAH025SUBP_3H.A2003003.1800.001.2015210044609.pss.grb
001
日付を表し、0000
時刻を示します。
フォルダにファイルがないことを確認する方法は? Googleはほとんど回答を得ていませんが、それを実装する方法がわかりません。
答え1
zsh
またはを使用すると、bash4
次のようになります。支柱の拡張その理由は次のとおりです。
ls -d GLDAS_NOAH025SUBP_3H.A2003{001..006}.{0000,0600,1200,1800}.001.2015210044609.pss.grb >/dev/null
括弧に注意してください。
{001..006}
001
、、002
...への拡張を表します。006
{0000,0600,1200,1800}
上記の各項目に0000
、0600
およびを追加します1200
。1800
>/dev/null
避けることですls
- >私たちはstderrに対してのみstdoutが欲しい
これでファイルが存在しない場合はls
エラーが表示されます。
ls: cannot access GLDAS_NOAH025SUBP_3H.A2003004.0000.001.2015210044609.pss.grb: No such file or directory
ls: cannot access GLDAS_NOAH025SUBP_3H.A2003004.0600.001.2015210044609.pss.grb: No such file or directory
ls: cannot access GLDAS_NOAH025SUBP_3H.A2003004.1200.001.2015210044609.pss.grb: No such file or directory
ls: cannot access GLDAS_NOAH025SUBP_3H.A2003004.1800.001.2015210044609.pss.grb: No such file or directory
ls: cannot access GLDAS_NOAH025SUBP_3H.A2003005.0000.001.2015210044609.pss.grb: No such file or directory
ls: cannot access GLDAS_NOAH025SUBP_3H.A2003005.0600.001.2015210044609.pss.grb: No such file or directory
ls: cannot access GLDAS_NOAH025SUBP_3H.A2003005.1200.001.2015210044609.pss.grb: No such file or directory
ls: cannot access GLDAS_NOAH025SUBP_3H.A2003005.1800.001.2015210044609.pss.grb: No such file or directory
ls: cannot access GLDAS_NOAH025SUBP_3H.A2003006.0000.001.2015210044609.pss.grb: No such file or directory
ls: cannot access GLDAS_NOAH025SUBP_3H.A2003006.0600.001.2015210044609.pss.grb: No such file or directory
ls: cannot access GLDAS_NOAH025SUBP_3H.A2003006.1200.001.2015210044609.pss.grb: No such file or directory
ls: cannot access GLDAS_NOAH025SUBP_3H.A2003006.1800.001.2015210044609.pss.grb: No such file or directory
を使用してにksh93
置き換えます。{001..006}
{1..6%.3d}
答え2
@chaosソリューションのバリエーション(bash 4.0以降またはzsh 4.3.11以降):
for a in GL.....2003{001..365}.{00..18..6}00.001.2015210044609.pss.grb
do
[[ -f $a ]] || echo "$a"
done
または
for a in {001..365}.{00..18..6}
do
[[ -f "GL.....2003${a}00.001.2015210044609.pss.grb" ]] || echo "$a"
done
欠けている日付+時間のみ印刷
答え3
しかし、カオスに対する答え対話型シェルで使用するのに理想的なこのスクリプトは、たとえば定期的におよび/または他のコンピュータでこれを行う必要がある場合は、POSIXスクリプトとして使用できます。
#!/bin/sh
i=0
while test "$((i+=1))" -lt 366 ; do
for j in 00 06 12 18 ; do
file="GLDAS_NOAH025SUBP_3H.A2003$(printf '%03d' "$i").${j}00.001.2015210044609.pss.grb"
test -e "$file" || echo "$file"
done
done
(seq
またはPOSIXは中括弧拡張を指定しません。)
答え4
ループ内でファイル名を作成し、ファイルが存在しないことをテストします。
for day in `seq -f "%03g" 1 30`
do
for hour in 0000 0600 1200 1800
do
filename="GLDAS_NOAH025SUBP_3H.A2003${day}.${hour}.001.2015210044609.pss.grb"
if [[ ! -e $filename ]]
then
echo "File missing: $filename"
fi
done
done
注:この例にエラーがないことを保証するものではありません。これは既知のジョブスクリプトではない例です。
移植性:ksh
または利用可能なGNUコマンドを持つシステムがbash
必要です。zsh
seq