I accidentally deleted some important image files using the following bash command, while I was trying to rename those files.
for file in *.jpg
do
mv "$file" "${file/*.jpg/$$$.jpg}"
done
Are these files moved somewhere, got hidden, or completely deleted? Is there any way to recover these files?
Thank you!
There are tools that can attempt to recover data of files which were deleted but not overwritten. (If a file is deleted, usually it's just 'unregistered', and the space that the actual data is in is marked as 'available', but not immediately overwritten). There's no promise that it'll succeed though.
Firstly i would like to say that unlike windows if a file is deleted in Linux it cannot be retrieved.
I can see that you have used mv "$file" "${file/*.jpg/$$$.jpg}" , $$ in Linux refers to the PID of the process and in your case it would refer to the PID of the bash process which will be the same in each case. Therefore a single file with the name PID$.jpg will be created i.e if your bash PID is 1234 the the file created will be 1234$.jpg and with each iteration the same file will be re-written.
I hope this makes sense.
If you wanted to write a script which would rename each file concatenated with the bash process id the below might be helpful. But test it once before you use it in production.
for file in *.jpg
do
mv "$file" `echo $file | awk -F "." '{print $1}'`.$$.jpg
done
karisha
try using file recovery software