LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 10-25-2021, 01:47 AM   #1
tjobful
LQ Newbie
 
Registered: Sep 2021
Location: Greece
Posts: 17

Rep: Reputation: Disabled
Accidentally replaced file -- How to retrieve??


Hey all!

I accidentally deleted a file, by saving another one ontop of it with the same name. Effectively replacing it. It happened using Pluma. All Pluma files.

It is not in the Trash. How can I get it back?

I am running Ubuntu Mate 20.4.

Thanks!!
 
Old 10-25-2021, 01:52 AM   #2
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,792

Rep: Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306
sorry guy, without details hard to say anything. Probably you can use your backup to restore your important files, you can try to reinstall packages, but we still have no any idea: how many files were removed/replaced, which files (binary/text files, own files or belongs to something), is it on a hdd or pendrive or ?, did you use that device afterward (for what?).
 
Old 10-25-2021, 04:56 AM   #3
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,294
Blog Entries: 3

Rep: Reputation: 3719Reputation: 3719Reputation: 3719Reputation: 3719Reputation: 3719Reputation: 3719Reputation: 3719Reputation: 3719Reputation: 3719Reputation: 3719Reputation: 3719
With most of the file systems, when you delete a file it is gone for good. So as mentioned above, you'll have to restore the file from one of your back up copies. If you don't have a daily backup routine in place, now is the time to begin. USB disks are rather cheap compared to the time invested in creating some of the files they preserve.

Looking forward, Ubuntu now supports the OpenZFS file system so you can do low-cost snapshots. Then that gives an extra way to retrieve the files as you could mount a snapshot and fish out the one file. However, you have to go out of your way to choose OpenZFS during installation as well as intentionally schedule snapshots. So that approach is more useful next time you do a full (re-)installation of Ubuntu.

Last edited by Turbocapitalist; 10-25-2021 at 04:57 AM.
 
Old 10-25-2021, 05:06 AM   #4
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 21,119

Rep: Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120
Quote:
Originally Posted by Turbocapitalist View Post
With most of the file systems, when you delete a file it is gone for good.
Say what ?.
The exact opposite is true - the on-disk data remains, but the inode pointer is gone. This is why forensic recovery is possible.

However, in this case, I would expect the same on-disk filesystem blocks to be re-used as the name hasn't changed. So the data really would be over-written. Purely speculation, I haven't run traces to scope this scenario.
 
Old 10-25-2021, 05:13 AM   #5
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,294
Blog Entries: 3

Rep: Reputation: 3719Reputation: 3719Reputation: 3719Reputation: 3719Reputation: 3719Reputation: 3719Reputation: 3719Reputation: 3719Reputation: 3719Reputation: 3719Reputation: 3719
Quote:
Originally Posted by syg00 View Post
The exact opposite is true - the on-disk data remains, but the inode pointer is gone. This is why forensic recovery is possible.

However, in this case, I would expect the same on-disk filesystem blocks to be re-used as the name hasn't changed. So the data really would be over-written. Purely speculation, I haven't run traces to scope this scenario.
I expect that at least one of those freed blocks gets overwritten rather soon after deletion, thus from an end-user perspective once it is deleted the file is gone for good.

Maybe Copy-On-Write might help, but that still would entail a lot of luck and taking the partition offline before later attempting something with specialized recovery software. With a lot of binary formats, even missing a bit destroys the file, not to mention what losing a whole block or two would matter. However, I'll defer to your experience here.
 
Old 10-25-2021, 05:20 AM   #6
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,792

Rep: Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306
Quote:
Originally Posted by syg00 View Post
However, in this case, I would expect the same on-disk filesystem blocks to be re-used as the name hasn't changed. So the data really would be over-written.
First the new file is written, and the old file will be removed afterward. But probably it depends on the filesystem implementation. So it will not be unconditionally overwritten. But the disk space will be freed and reused [sometimes, later], so if you are fast enough and can umount that filesystem [before even a partial overwrite] the given file could be still recoverable (just need to know where is it exactly located).
 
Old 10-25-2021, 05:34 AM   #7
hazel
LQ Guru
 
Registered: Mar 2016
Location: Harrow, UK
Distribution: LFS, AntiX, Slackware
Posts: 7,564
Blog Entries: 19

Rep: Reputation: 4446Reputation: 4446Reputation: 4446Reputation: 4446Reputation: 4446Reputation: 4446Reputation: 4446Reputation: 4446Reputation: 4446Reputation: 4446Reputation: 4446
It is well worth creating aliases for the cp, rm and mv commands
Code:
alias cp='cp -i'
alias rm='rm -i'
alias mv='mv -i'
Put that into one of your bash startup files, either .bashrc or some file that .bashrc runs; some distros have a specific .bash_aliases file for this sort of thing. Then, as long as you are working on the command line, your system will never again remove or overwrite an existing file without asking you first.

Last edited by hazel; 10-25-2021 at 05:37 AM.
 
Old 10-25-2021, 07:12 AM   #8
shruggy
Senior Member
 
Registered: Mar 2020
Posts: 3,670

Rep: Reputation: Disabled
@hazel. Good advice, but, unfortunately, wouldn't help in this case. The OP overwrote a file by saving to it from a text editor buffer.

@OP. Does Pluma create automatic backups of edited files? Something like filename~? Pluma is a fork of gedit, and gedit has this in its preferences: Create a backup copy of files before saving (unchecked by default).

Last edited by shruggy; 10-25-2021 at 07:19 AM.
 
Old 10-25-2021, 07:20 AM   #9
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,294
Blog Entries: 3

Rep: Reputation: 3719Reputation: 3719Reputation: 3719Reputation: 3719Reputation: 3719Reputation: 3719Reputation: 3719Reputation: 3719Reputation: 3719Reputation: 3719Reputation: 3719
Pluma is not set to do that by default. It has to be configured to do so: Edit -> Preferences -> Editor -> File Saving (Create a backup copy ...) That will keep the previous version of filename as filename~
 
  


Reply

Tags
deleted, recover, replaced, ubuntu mate


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
c program to generate a string with replaced values in a file. arungpillai09054 Programming 4 03-25-2013 11:33 AM
thunar does not update date and time when a dot file is replaced allend Slackware 2 10-27-2012 04:36 PM
How to retrieve that I kill accidentally gerard.zapata Linux - Newbie 7 07-06-2011 08:03 PM
Thunar accidentally replaced Nautilus as Gnome's default window manager! Cyberman Linux - Software 9 04-15-2009 07:02 AM
cp or mv: skipping file...it was replaced da_kidd_er Linux - General 3 10-21-2004 01:56 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 08:26 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration