恢复使用rm命令删除的文件 [英] recover files deleted with rm command

查看:65
本文介绍了恢复使用rm命令删除的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请运行我的命令

#  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

推荐答案

如果创建像这样的已删除目录,则可能会出现某些意外行为.例如:

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

将创建一个单独的文件test.txt,其内容位于 other_dir 中.启动rm_scripting/移动目录时,会更加有趣.

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.

知道了这一点,并再次引用了scrap-cli(请参阅注释Aserre),您可能会:

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.

这篇关于恢复使用rm命令删除的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆