问题
Please if I run the command
# CREATE TRASH FOLDER
if ! [ -d "$HOME/deleted" ] ; then
mkdir $HOME/deleted
fi
TRASH=$HOME/deleted
mv $@ $TRASH
To move file or directory to the trash created. what is the possible command i can run to recover same file to the original directory
回答1:
If you create a deleted directory like this, you will probably get some unexpected behavior. For example:
rm_script test.txt
cd ../other_directory
rm_script test.txt
will create a single file test.txt with the content of the one in other_dir
. Even more fun when you start rm_scripting/moving directories.
Knowing this, and referring once more to trash-cli (see comment Aserre), you might:
if ! [ -d "$HOME/deleted" ] ; then
echo "What a pity! No deleted directory."
echo "Your file(s) is/are lost forever!"
exit 361
fi
TRASH=$HOME/deleted
for file in $@ ; do
if [ -f "$TRASH/$file" ] ; then
cp "$TRASH/$file" .
else
echo "Hmm,.. I cannot find $file."
fi
done
This also may have some unwanted results, like removing the file from one directory and un-deleting it in another.
回答2:
I just do the reverse of the same command line
function undo () {
echo -n "Do you want to recover $*? "
read ANSWER
if [ "$ANSWER" = "y" ]; then
mv $TRASH/$@ $PWD
echo "$@ successfully recovered"
else
echo "Oops, request denied"
fi
}
来源:https://stackoverflow.com/questions/49029467/recover-files-deleted-with-rm-command