Page 1 of 1

undo removed file with rm

PostPosted: Mar 1st, '20, 11:57
by ovince
Dear All,

I accidentally deleted a .bashrc file from /root (as administrator) with the rm command. Is there a way to recover the file? I supplemented this file with features that made it easier for me to work on my computer and desperately seek help

Thank you in advance
Oliver

Re: undo removed file with rm

PostPosted: Mar 1st, '20, 12:07
by doktor5000
It depends on what filesystem is used for the / partition. If it's ext4, then have a look at
https://wiki.archlinux.org/index.php/Fi ... xtundelete or https://wiki.archlinux.org/index.php/Fi ... #Ext4Magic
Although ext4magic is not available via the Mageia repositories, you would have to install it manually.

If your / partition is not ext4, then please mention what filesystem is used. To check what filesystem is used, post the output of
Code: Select all
mount | grep  '/ '


If you only want to recover the file without your additions, you can just copy it over from /etc/skel/.bashrc

Re: undo removed file with rm

PostPosted: Mar 1st, '20, 18:07
by ovince
thank you for fast reply.

It is ext4 and I have installed Ext4Magic. According to the instructions, I should mount the FS (/dev/sda2) as read-only. So I did:

Code: Select all
mount -o remount,ro,noload  /dev/sda3


but there is a message that 'the /home is busy' despite the fact that I killed all processes that I gave found with

Code: Select all
ps aux | grep home



Do you have some additional suggestions?

Re: undo removed file with rm

PostPosted: Mar 1st, '20, 19:17
by doktor5000
ovince wrote:According to the instructions, I should mount the FS (/dev/sda2) as read-only. So I did:

Code: Select all
mount -o remount,ro,noload  /dev/sda3

You wrote that you want to remount sda2 readonly, but ran the command against sda3 (which seems to be your /home partition).
But in the first post you mention you want to restore /root/.bashrc - this is not located in your /home partition.

Also, you cannot use ps to check for open files, you would need to use fuser or lsof for that.

Re: undo removed file with rm

PostPosted: Mar 1st, '20, 21:52
by ovince
sorry, I meant sd3

I used to have /home/.bashrc (sda3) and its symbolic link in /root/.bashrc. to be able to use some functions by both users (probably clumsy solution ...). But, today I deleted /root/.bashrc forgetting that it was a link, so I end up loosing all ....

Re: undo removed file with rm

PostPosted: Mar 2nd, '20, 00:01
by doktor5000
If /root/.bashrc was a symlink to /home/.bashrc then you only need to recreate that symlink.