Bashスクリプトでは、次のコマンドを使用して特定のディレクトリから最新のバックアップファイルをインポートします。
find /mnt/synology/bk/ -maxdepth 1 -name 'bk-*' -mmin -60 -print0 | xargs -0 ls -1 -t 2>/dev/null | head -n 1
ファイルが見つからない場合、コマンドは現在のディレクトリ(コマンドが実行されている場所)にあるファイルを返します。
一致するファイルがない場合は空の出力を返すことはできますか?
ありがとう
ベストアンサー1
xargsの-rオプションを試してください。
-r, --no-run-if-empty
If the standard input does not contain any nonblanks, do not run the command. Normally, the command is run once even if there is no input. This option is a GNU extension.