需要帮助。这是我用来将文件从垃圾箱目录还原到其原始位置的脚本。它以前位于根目录中。然后使用其他脚本将其“删除”并存储在垃圾箱目录中,并使用以下方式在存储文件中记录其以前的位置:
case $ans in
y) echo "`readlink -f $1`" >>home/storage & mv $1 /home/dustbin ;;
n) echo "File not deleted." ;;
*) echo "Please input answer." ;;
esac
当使用下面的脚本时,我应该能够恢复已删除的文件,但是会出现以下错误。
#!/bin/sh
if [ "$1" == "-n" ] ; then
cd ~/home/dustbin
restore="$(grep "$2" "$home/storage")"
filename="$(basename "$restore")"
echo "Where to save?"
read location
location1="$(readlink -f "$location")"
mv -i $filename "$location1"/$filename
else
cd ~/home
storage=$home/storage
restore="$(grep "$1" "$storage")"
filename="$(basename "$restore")"
mv -i $filename $restore
fi
错误提示 - mv: 缺少文件操作数
编辑:
所以好吧,我把我的脚本改成了这样。
#!/bin/sh
if [ $1 ] ; then
cd ~/home
storage=~/home/storage
restore="$(grep "$1" "$storage")"
filename="$(basename "$restore")"
mv -i "$filename" "$restore"
fi
但是我仍然遇到错误:
mv: 无法查找“filename”:没有那个文件或目录
mv
行之前添加echo "<$filename> <$restore>"
(并类似地添加到第一个)以查看正在发生的情况。 - choroba[bash] restore file
返回了许多已经得到解答的问题。祝你好运。 - shellter