unix 下的恢复功能

unix 下的恢复功能

我有一个脚本可以将文件恢复到原始位置。我缺少脚本的选项“您想恢复此文件吗?”是或否。我将如何将其实现到下面的代码中谢谢!

#!/bin/bash
if [[ ! $1 ]]; then
echo -e "Usage:\n\n\t$0 'file name'"
exit 1
fi

f=$(ls 2>/dev/null -l /proc/*/fd/* | fgrep "$1 (deleted" | awk '{print $9}')

if [[ $f ]]; then
   echo "fd $f file found..."
cp -v "$f" "$1"
   else
echo >&2 "No file"
exit 2
fi
 }

答案1

用于read请求确认,例如:

echo "fd $f file found..."
read -p "Press enter to continue or Ctrl+c to cancel"
cp -v "$f" "$1"

或者

echo "fd $f file found..."
read -p "Do you want to recover this file? [Yes/No] " confirmation
[[ $confirmation =~ ^[YyJj] ]] || { echo "Canceled"; exit }
cp -v "$f" "$1"

相关内容