0

I have a script to move files to a save folder called trash.

#  CREATE TRASH FOLDER

if ! [ -d "$HOME/deleted" ] ; then
     mkdir $HOME/deleted
fi

TRASH=$HOME/deleted
mv $@ $TRASH

How do I create a log file for the paths its deleted from and how to get the path.

Destiny Alabi
  • 71
  • 1
  • 10
  • How are you passing the arguments to the script. And remember `mv` does _not_ delete files in the sense you are referring to. It just moves them to another location in the disk – Inian Mar 01 '18 at 10:11
  • Can you elaborate more? It is not clear here. – Abhijit Pritam Dutta Mar 01 '18 at 10:17
  • Looks so similar to your older question - https://stackoverflow.com/questions/49029467/recover-files-deleted-with-rm-command – Inian Mar 01 '18 at 10:39
  • @AbhijitPritam Pritam I have a similar script to the RM command, but here it only move to a separate location call TRASH. mv $@ $TRASH 2>/dev/null when i tried to recover back, it goes to my working directory mv "$TRASH/$file" $PWD instead of the location it was moved from. What i want is how to get the path it was moved from and recover it back to same path. – Destiny Alabi Mar 01 '18 at 10:45
  • Yes @Inian Still on the same project – Destiny Alabi Mar 01 '18 at 10:45
  • Are you providing your path `$@` here? Like `mv /app/myapp/log.txt $TRASH`? – Abhijit Pritam Dutta Mar 01 '18 at 11:04
  • Also provide detail about `$@`. Just do `echo $@` and provide us the details. – Abhijit Pritam Dutta Mar 01 '18 at 11:18
  • $@ is the argument passed. so if i run my script with **saferm logo.png**, the logo.png which is now the $@ will be moved to trash. – Destiny Alabi Mar 01 '18 at 11:27
  • you can find out the full path of your argument using `readlink` and `dirname`. See https://stackoverflow.com/questions/17577093/how-do-i-get-the-absolute-directory-of-a-file-in-bash Store the result wherever you want.This allows you to specify only filename as an argument. But your solution can cause many troubles, for example when you move files of the same name from different directories. Consider another backup or file versioning system. – dr_agon Mar 03 '18 at 15:50

0 Answers0