# Help Writing File Restore Script

**URL:** <https://community.unix.com/t/help-writing-file-restore-script/366014>\
**Category:** Shell Programming and Scripting\
**Created:** [April 7, 2017, 4:04pm UTC](https://community.unix.com/t/help-writing-file-restore-script/366014 "2017-04-07T16:04:56Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![bashbeginner](https://community.unix.com/letter_avatar/bashbeginner/32/6_449c533f586939b6e5f246632a46421f.png) [@bashbeginner](https://community.unix.com/u/bashbeginner)\
**Post date:** [April 7, 2017, 4:04pm UTC](https://community.unix.com/t/help-writing-file-restore-script/366014/1 "2017-04-07T16:04:56Z")

</div>

Hi all,

I have been tasked with creating a script that sends a file into a created "recycling" directory and another script that restores a "deleted" file. I have already created the removal script but am stuck on the restoring part.

I need to restore the file to its original location by using its path name, which can be found in the .restore.info file that I created.

Here is the removal script:

```nohighlight

# did the user enter a filename
if [-z "$1"]; then
echo "No file was entered"
exit
fi

# warns the user if a directory and not a file was entered
if [-d "$1"]; then
echo "Directory name entered. Please enter file name"
exit
fi

# if the correct file name is entered then display file deleted
if [! -f "$1"]; then
echo "$1 Does not exist"
exit
fi

# finds inode of a file to avoid files with the same name
inode=$(stat -c '%i' $1) 2>/dev/null

# shows the path of the file
path=$(readlink -f "$1") 2>/dev/null

# prints name of the file and its path in the .restore.info file
echo "$1_$inode:$path" >> ~/.restore.info 2>/dev/null

# warns the user if they enter this script as an argument
if [$1 = "remove123"]; then
read -p "Are you sure you want to delete remove? y/n: " answer

#if yes, then remove the file otherwise do nothing
if [[$answer = y]] ; then
        mv "$1" deleted/"$1"_"$inode" 2>/dev/null
        echo "$1_$inode:$fixedPath" >> ~/.restore.info 2>/dev/null
else
        exit
fi
fi

#moves to deleted dir
mv "$1" deleted/"$1_$inode" | cut -d " " -f 1 2>/dev/null

```

So far for my restore script, I have:

```nohighlight
#find the original path of the file
path=$(readlink -f "$1/.restore.info") 2>/dev/null

#move the file back to its original path
mv $1 $path

```

Please forgive me for my basic language, I'm very new to Unix programming.
