Skip to content

Instantly share code, notes, and snippets.

@computercam
Created April 30, 2020 04:09
Show Gist options
  • Select an option

  • Save computercam/e294b20cd16fe4c868d0634e6a6a5071 to your computer and use it in GitHub Desktop.

Select an option

Save computercam/e294b20cd16fe4c868d0634e6a6a5071 to your computer and use it in GitHub Desktop.

Revisions

  1. Cam Sanders created this gist Apr 30, 2020.
    22 changes: 22 additions & 0 deletions ext4magic_recover_text.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,22 @@
    # Recover files from ext4magic based on the path to the missing textfile
    # After running ext4magic -m /path/to/device, from the directory containing RECOVERDIR, run this script with the path to the directory containing text files you want to recover.
    # Example:
    # ext4magic_recover_text.sh /home/cameron/lostfiles

    function get_timestamp() {
    date -d @${1} | cut -d' ' -f1-6 | sed 's/ /_/g'
    }

    for file in $(grep -Rl $1 ./RECOVERDIR/ 2> /dev/null)
    do
    filename=$(grep "^file://$1" $file | cut -d' ' -f1 | cut -d/ -f7- | sed 's/\//-/g')
    timestamp=$(grep "^file://$1" $file | cut -d'"' -f3 | cut -d':' -f2 | cut -d, -f1)
    if [[ -n "$filename" && "$filename" != "Binary" ]]
    then
    timestamp=$(get_timestamp $timestamp)
    filename="$filename-$timestamp"
    cp -f $file ./${filename}
    else
    cp -f $file ./
    fi
    done