Search
 
SCRIPT & CODE EXAMPLE
 

SHELL

linux recover deleted file

#!/bin/bash

# sometimes I can recover deleted files with this script
if [[ ! $1 ]]; then
    echo -e "Usage:

	$0 'file name'"
    exit 1
fi

f=$(file 2>/dev/null /proc/*/fd/* | awk '$NF == "(deleted)"{print $(NF-1)}')

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

# There's another useful trick: if you know a pattern in your deleted files, type alt+sys+resuo to reboot+remount in read-only, then with a live-cd, use grep to search in the hard-drive
grep -a -C 500 'known pattern' /dev/sda | tee /tmp/recover
Comment

PREVIOUS NEXT
Code Example
Shell :: setting docker as a non root user 
Shell :: view available pips 
Shell :: new ssh key github 
Shell :: git add ssh 
Shell :: kivy install ubuntu 20 
Shell :: revert git add 
Shell :: pm2 process disappears after reboot 
Shell :: vscode Error: EACCES: permission denied 
Shell :: list number of files in each folder linux 
Shell :: how to download 
Shell :: git new branch 
Shell :: git login 
Shell :: git how to see changes made by a commit 
Shell :: fedora linux 
Shell :: batch escape character 
Shell :: sudoer sudo no password NOPASSWORD 
Shell :: check gcp disk space usage 
Shell :: reconfigure gitlab 
Shell :: bash for i 
Shell :: how to sort tags on git tag 
Shell :: make pm2 auto-boot at server restart 
Shell :: force remove hidden folder in linux 
Shell :: find file linux 
Shell :: loop array bash 
Shell :: make changes to a previous commit 
Shell :: cannot send file to server with nginx 
Shell :: Regex: Match Last Occurrence aka Negative Lookbehind 
Shell :: remove folder from git repository 
Shell :: shorten the linux terminal path 
Shell :: bash get domain from url 
ADD CONTENT
Topic
Content
Source link
Name
3+1 =