'rm -rf ~0/' ruined my ubuntu because I want to delete a temporary folder named 0 while current folder is my home

Billhong1998

New Member
Joined
Jun 17, 2022
Messages
2
Reaction score
0
Credits
19
I have tried TestDisk. It asked:

To repair the filesystem using alternate superblock, run fsck.ext4 -p -b superblock -B blocksize device

Next I issued: sudo fsck.ext4 -p -b 2654208 -B 4096 /dev/sda

Response: /dev/sda is in use. e2fsck: Cannot continue, aborting.

I am not sure I could repair it and not sure if there is any hope.

Any help is appreciated.
 


Condobloke

Well-Known Member
Joined
Apr 30, 2017
Messages
4,638
Reaction score
4,028
Credits
26,271
G'day Billhong, Welcome to Linux.org

As far I know, the drive being used cannot be used to run fsck

do you have a usb stcik with your OS on it?....if so boot to that usb stick and carry out the fsck procedure from there
 
OP
B

Billhong1998

New Member
Joined
Jun 17, 2022
Messages
2
Reaction score
0
Credits
19
G'day Billhong, Welcome to Linux.org

As far I know, the drive being used cannot be used to run fsck

do you have a usb stcik with your OS on it?....if so boot to that usb stick and carry out the fsck procedure from there
Thank you for your reply.

I can make a bootable USB stick and I will try TestDisk again later.
 

Tolkem

Well-Known Member
Joined
Jan 6, 2019
Messages
1,455
Reaction score
1,176
Credits
10,561
You need to be very careful with commands like rm, rmdir, dd ... if you make a typo or some other kind of mistake, it can lead to disaster, just like you've just experienced. For removing files/dirs or partition drives, I prefer a GUI approach where possible.
 

SlowCoder

Gold Member
Gold Supporter
Joined
May 2, 2022
Messages
456
Reaction score
313
Credits
3,611
rm -rf ~0/ is wrong. I'm not sure what ~0 would remove.
rm -rf ~/0 is right, and would remove a directory called 0 in your home directory.
Running the above commands would not corrupt your filesystem, only remove data within.

Running fsck would not help in this scenario, and will not recover deleted files. fsck is for repairing a dirty/unclean/corrupted ext filesystem.
 

Tolkem

Well-Known Member
Joined
Jan 6, 2019
Messages
1,455
Reaction score
1,176
Credits
10,561
Last edited:

Rob

Administrator
Staff member
Joined
Oct 27, 2011
Messages
914
Reaction score
1,728
Credits
1,123
Yeah, I think ~0 is either ignored or is cwd?
Code:
[rob test ]$ ls
50.yaml  50.yaml.bk
[rob test ]$ ls ~0/
50.yaml  50.yaml.bk
[rob test ]$ ls ~1/
ls: cannot access '~1/': No such file or directory

But yeah, SLowcoder is right, you didn't damage your disk, you deleted files..
 

SlowCoder

Gold Member
Gold Supporter
Joined
May 2, 2022
Messages
456
Reaction score
313
Credits
3,611
Yeah, I think ~0 is either ignored or is cwd?
Code:
[rob test ]$ ls
50.yaml  50.yaml.bk
[rob test ]$ ls ~0/
50.yaml  50.yaml.bk
[rob test ]$ ls ~1/
ls: cannot access '~1/': No such file or directory
Here's some further explanation on how bash interprets telde: https://wiki.bash-hackers.org/syntax/expansion/tilde

From the explanation, I don't quite understand how ~0 would delete files though. OP doesn't explain what files were deleted.
 

Tolkem

Well-Known Member
Joined
Jan 6, 2019
Messages
1,455
Reaction score
1,176
Credits
10,561
I don't quite understand how ~0 would delete files though.
I think because he used -rf and by man rm:
Bash:
-f, --force
              ignore nonexistent files and arguments, never prompt
Also, doing ls ~0/ here lists all my $HOME files and folders, so I guess he deleted everything there. I think OP might be able to boot from a live USB, mount the partition, and recreate home from there. Sadly, since he's been messing with that, there's probably 0 chance to recover any file. Something like this https://forums.linuxmint.com/viewtopic.php?t=135265
 

Tolkem

Well-Known Member
Joined
Jan 6, 2019
Messages
1,455
Reaction score
1,176
Credits
10,561
~0/ doesn't point to the user's home directory.
Ok. Then why:
Bash:
ls ~0/
 _bashrc.new           Descargas    Escritorio       kxstudio-repos_11.1.0_all.deb   merged-preseed   Plantillas       tutorial1   Wallpapers
 advice            bin                Documentos   genmon-scripts            Música           Público          txts
 Appimages    Documents    Imágenes        'MEGAsync Downloads'             neon-link        pulse-pkgs.txt   Vídeos
But:
Bash:
ls ~1/
ls: cannot access '~1/': No such file or directory
Or
Bash:
ls ~2/
ls: cannot access '~2/': No such file or directory
I'd expect to get the same thing with either any of those; ls: cannot access '~0|1|2/': No such file or directory since it doesn't exist; I don't have any dir or file named 0 in my $HOME.
And it gets even more interesting
Bash:
ls ~00/
_bashrc.new        Descargas    Escritorio       kxstudio-repos_11.1.0_all.deb   merged-preseed   Plantillas       tutorial1   Wallpapers
 advice            bin                Documentos   genmon-scripts                  Música           Público          txts
 Appimages            Documents    Imágenes        'MEGAsync Downloads'             neon-link        pulse-pkgs.txt   Vídeos
And
Bash:
ls ~01/
ls: cannot access '~01/': No such file or directory
Oh, yeah
Bash:
ls ~02/
ls: cannot access '~02/': No such file or directory

Now, this got me really curious; I tried with 10 zeros! It still lists the files and dirs in my $HOME! But only zeros, whenever I use any number, even something like 00000000001 I'd get the No such file or directory error!
 
Last edited:

osprey

Member
Joined
Apr 15, 2022
Messages
77
Reaction score
43
Credits
672
Rob wrote:
~0/ doesn't point to the user's home directory
....
it points to your current working directory.
Thanks for the correction. The context which I had in mind was of the command being run in the home directory of the OP which resulted in its loss, though my text appeared more generalised which was not intended.
 

captain-sensible

Well-Known Member
Joined
Jun 14, 2019
Messages
2,856
Reaction score
1,931
Credits
17,660
G'day Billhong, Welcome to Linux.org

As far I know, the drive being used cannot be used to run fsck

do you have a usb stcik with your OS on it?....if so boot to that usb stick and carry out the fsck procedure from there
yep thats right , you can't run on a mounted drive; in days gone by you could do it with Slackware by dropping run levels and one or 2 other commands that I have forgotten
 
$100 Digital Ocean Credit
Get a free VM to test out Linux!

Linux.org Hosting Donations
Consider making a donation


Top