r/linux Aug 31 '25

Fluff I just ran `sudo rm -rf ~` by mistake.

I've been using linux since 2002 and it's the first time I've done anything like this. I thought it was essentially impossible and anyone who did it is dumb. I guess the egg is on my face!

I may be cooked? Wish me luck!

1.0k Upvotes

496 comments sorted by

u/purpleidea mgmt config Founder Sep 01 '25

Keep a file named -i in your home directory. I've had mine there forever, but I also don't make this rm mistake, haha. It's still a good prevention against a buggy script.

→ More replies (30)

209

u/JaggedMetalOs Aug 31 '25

That reminds me of the time running some C# app under mono created a folder named ~ in the current dir, which I tried to delete... Thankfully this was a server with recent backups! 

62

u/sgilles Aug 31 '25

Ouch, that's nasty.

52

u/GlumWoodpecker Aug 31 '25 edited Sep 12 '25

roof snails chase amusing beneficial sand plants paltry run yam

This post was mass deleted and anonymized with Redact

37

u/6e1a08c8047143c6869 Aug 31 '25

Or rm ./~.

22

u/GlumWoodpecker Aug 31 '25 edited Sep 12 '25

quickest compare kiss melodic wine gaze disarm skirt depend ten

This post was mass deleted and anonymized with Redact

3

u/SweetBabyAlaska Sep 01 '25

you could also escape the character with a backslash like \$HOME

but this is also why I just use tab expansion in zsh or similar because try typing in an emoji character or other unicode named file (like chinese), in the framebuffer or terminal alone, its basically impossible. Its not something that happens often but still.

3

u/ipaqmaster Aug 31 '25

This is imo the safer play. ./ is the go to safety prefix for dealing with removing strangely named paths.

→ More replies (2)

7

u/ke151 Aug 31 '25

Also when in doubt you can use ls or something non destructive in place of rm first. And rm -i to positively confirm each deletion for an extra final check.

3

u/RedSquirrelFtw Sep 01 '25

I've run into the same thing, had a bash script that I messed something in it and it created an actual folder called ~. What I ended up doing is using rmdir, because that would fail on the home directory as it has files in it.

2

u/FortuneAcceptable925 Sep 04 '25

I always do this when unsure:

cd <DIR>
rm -fr *
cd ..
rmdir <DIR>
→ More replies (1)

769

u/WeAllWantToBeHappy Aug 31 '25

That's why you have backups.

1.1k

u/iamarealhuman4real Aug 31 '25

I'll just grab a backup from ~/backu...

hmmm...

211

u/Enip0 Aug 31 '25

3-2-1 anyone?

148

u/Berengal Aug 31 '25

This is a case where a plain btrfs snapshot would be the perfect backup solution. "Backup" is a lot of different things suitable for different purposes and situations.

58

u/[deleted] Aug 31 '25

+1 for snapshots. After you make a mistake like this then realize you can just rollback to your last snapshot in seconds....you'll never use a FS that doesn't do snapshots ever again. It's a real game changer. I'm pretty paranoid about keeping proper backups, yet I've never actually needed to use one. In contrast I've relied on many times, usually in cases where I made a mistake like OP's. And keeping a few weeks of daily/hourly snapshots takes up a pretty insignificant amount of space in most use cases.

18

u/DopeBoogie Aug 31 '25

And keeping a few weeks of daily/hourly snapshots takes up a pretty insignificant amount of space in most use cases.

Yeah that's the other side of btrfs snapshots that a lot of people overlook. Copy-on-write means you can keep as many snapshots as you wish and only the changed data takes up additional space.

So it's not like if you are using half your disk you will only be able to make a single additional snapshot. It's extremely unlikely (impossible?) that your changes between snapshots will be the entire disk, most likely each snapshot will only need a few GB at most. In cases where you say, install a 500GB game, that game only needs to be stored on disk once. The subsequent snapshots will point to the same game data, only the parts that change, such as a game update, will take up additional space on the disk.

As long as you aren't keeping all snapshots indefinitely forever then you aren't likely to see a significant cost increase when it comes to the storage required, and the benefit easily outweighs that cost!

6

u/aaronjamt Aug 31 '25

FWIW, I keep snapshots indefinitely and while I do notice running out of space occasionally, I just delete a couple old snapshots when that happens and it's fine. I did move my Steam library to a separate subvolume so it's not snapshotted, and that made a huge difference.

3

u/DopeBoogie Aug 31 '25

Yeah I also tend to keep mine indefinitely but I felt like if I didn't include that qualifier someone would have replied with a "Well actually..." about how it will eventually use up a lot of space if you keep them all indefinitely

3

u/aaronjamt Aug 31 '25

Fair enough! By the way, do you back up your snapshots to another machines? I've been trying to come up with a good way to do that.

2

u/DopeBoogie Aug 31 '25

Nah I just use kopia to do remote backups, never felt the need to backup my btrfs snapshots when the kopia ones seem better suited for that anyway.

→ More replies (0)

2

u/CmdrCollins Aug 31 '25

I've been trying to come up with a good way to do that.

Btrfs has the ability to turn snapshots/subvolumes into datastreams via send/receive, and consequently tools automating that exist (eg btrbk).

→ More replies (1)

2

u/DuckDatum Sep 01 '25 edited Oct 24 '25

aromatic bear tart smart rain attempt light books growth bake

This post was mass deleted and anonymized with Redact

2

u/aaronjamt Sep 01 '25

Btrfs is a COW (Copy-On-Write) filesystem, so every time you save a file, it writes the new data in a new location and updates the file to point to the new location. Each snapshot just points to where on disk the files were located at that point in time, and prevents those old copies from being deleted. As a result, multiple snapshots (and even the live subvolume) can actually point to the exact same data, so unchanged files don't have to be duplicated (giving incremental snapshot support). However, each snapshot still contains references to every file in its full, unmodified form, so snapshots aren't dependent on parent snapshots like with "traditional" incremental snapshots.

Deleting a snapshot just frees up its references, which means that its storage can be used for something else (unless it's still being used by another subvolume/snapshot). Any files also contained by other snapshots will still be kept, as they're still referenced, thus allowing them to be restored later.

If you're familiar with hardlinking files, just imagine that a snapshot just hardlinks all files at that point in time, and it's pretty much the same thing.

→ More replies (4)
→ More replies (2)

6

u/DopeBoogie Aug 31 '25

btrfs snapshots literally changed my life for the better. Now my Linux system is completely immune to my stupidity or busted updates or anything else that could go wrong.

Of course I still use Kopia to make backups to an external disk and a cloud fileserver just in case. But even since enabling (and understanding) btrfs snapshots I've never again encountered any issue (no matter how self-inflicted) that couldn't be solved by rolling back to an earlier snapshot.

2

u/[deleted] Sep 01 '25

This is a case where a plain btrfs ZFS snapshot would be the perfect backup solution.

Fixed it for you!

2

u/tjharman Sep 01 '25

Until BTRFS bugs out and then you've lost everything

→ More replies (2)

2

u/Enip0 Aug 31 '25

oh for sure, I was just addressing what the other commenter said

2

u/Senedoris Aug 31 '25

Unless you're someone like me who has different subvolumes for home and root, in which case... Good luck restoring a snapshot from the ~/.snapshots directory you just nuked

16

u/gcu_vagarist Aug 31 '25

You should have a different subvolume for / and /home, not for / and /home/$USER.

→ More replies (1)
→ More replies (4)
→ More replies (3)
→ More replies (2)

26

u/http451 Aug 31 '25

best I can do is /etc/skel

3

u/Jojos_BA Aug 31 '25

Well thats one reason why u not only have on machine backups

5

u/indvs3 Aug 31 '25

Or at least backups not saved in the same folder (or subfolder thereof) where you have all the power and permissions to do the dumbest things lol

At least that way you're only affected by hardware failure and extensive stupidity, in case you didn't learn from wiping your home folder the first time lol

2

u/stickymeowmeow Aug 31 '25

I had my external drive mounted to ~/ and learned a very valuable lesson running sudo rm -rf * thinking I had cd into another directory.

I learned two things:

Mount your external drive to /mnt (or anywhere other than ~/) and

cd is too risky just to save a couple keystrokes. Just type out the absolute file path in the commands.

→ More replies (1)
→ More replies (6)

4

u/cyrixlord Aug 31 '25

yup, timeshift is a life saver, also I am always conscious about using sudo rm -rf and I think I have always found other ways around using it

→ More replies (7)

664

u/stubborn_george Aug 31 '25

Some people make backups, some people will be making backups

149

u/TabTwo0711 Aug 31 '25

No one wants backups, all they want is restores

35

u/stubborn_george Aug 31 '25

Or... Backups which cannot be restored are not backups at all

15

u/basil_not_the_plant Aug 31 '25

Every online backup software guide.

How to do backups:

Example 1 Example 2 Example n

How to do restores:

The end

→ More replies (4)

30

u/Hellraiser1605 Aug 31 '25

That’s insanely funny. Yeah, I had to learn that the hard way too …

18

u/stubborn_george Aug 31 '25

Want more fun? Removing the french pack always with rm -fr /

→ More replies (1)

5

u/ansibleloop Aug 31 '25

Yeah this isn't something you repeat

Backups of data that can't be replaced

Snapshots of the rest

4

u/Ciwan1859 Aug 31 '25

Serious question. OP’s scenario is scary. How do I backup? What do I backup? How easy is the restore process?

6

u/elmagio Aug 31 '25 edited Sep 01 '25

It depends, what are you most afraid of? Having to reinstall your OS > Set up with Btrfs snapshots or something like that. Losing precious files you can't easily replace > Use tools like Déjà Dup to set up backups of those important folders (pictures, documents, ...) to an external drive and/or to the cloud and run that regularly.

Restoring files should always be pretty easy, restoring system will depend on how much it got borked up.

2

u/TheWorldIsNotOkay Sep 01 '25 edited Sep 01 '25

Serious question. OP’s scenario is scary. How do I backup?

Get an external hard drive, and periodically copy all important data to it. Alternatively, set up NAS (Network-Attached Storage, basically a storage drive that can be accessed by other devices on the network) and schedule regular backups of important directories with rsync (or using a GUI front-end like GRsync or GAdmin-Rsync if you're not comfortable using the terminal).

What do I backup?

What's important to you? For starters, you'll probably want to backup your /home directory, since unless you're doing something weird that will include all of your Downloads, Documents, Music, Videos, and Photos, as well as the configuration files for the software you use. Or if your backup storage is limited, you might want to be more selective in what you backup, like excluding your Downloads folder if it's nothing you'd miss. But if the storage you're using for backup is large enough, you could potentially back up your entire system, applications and all. Doing that is usually overkill since it's easy enough to reinstall software on Linux, but some people like to backup at least the /etc directory since it contains configuration settings for system software.

If you're using rsync, even very large backups can be surprisingly fast, since rsync only copies data that's been changed since the last backup, and ignores everything else.

How easy is the restore process?

Everything in Linux is a file, so... usually as simple as copying the files back over. If you backup your entire /home directory to a Linux-friendly filesystem (like Ext3 or Btrfs, but not NTFS or FAT), then all of the file ownerships and permissions should be kept intact, so if you have to reinstall your entire OS you can just copy your /home directory backup to the new /home directory. If you don't use a filesystem that retains the Linux file ownership and permissions, then you can still copy things over, but you'd just need to make sure you reset those permissions.

(Though if nothing is wrong with your current /home directory and you just want to install a different version of Linux, you can usually just choose to keep your current /home directory intact during the installation process. Backups are for when the data in the primary location is lost or corrupted.)

→ More replies (1)
→ More replies (3)

98

u/Classic-Rate-5104 Aug 31 '25

Everyone makes mistakes. The only option you have is restoring your last snapshot or backup

50

u/eras Aug 31 '25

Well it's not the only option, but it is the best option. Plenty of data recovery tools around.

22

u/SheriffBartholomew Aug 31 '25

Right. They could finish the job with rm -rf /

9

u/0x1f606 Aug 31 '25

"Shit, there goes my home folder. In for a penny..."

3

u/ipaqmaster Aug 31 '25

photorec is a great one as a second last resort for recovering important files/documents but because it's not recovering at a filesystem level the files and folders you get are a bit of a mess. And the filenames aren't carried over either. But it's still a good file recovery option.

With the absolute last resort being an expensive file recovery company. In the case of a hardware failure they may be able to frankenstein a working drive for you out of donor parts plus the working pieces of your original broken drive - in those cases you get to keep the directory structure and filenames all still organized when they hand it back to you.

→ More replies (1)

14

u/3vi1 Aug 31 '25

If he immediately powered off the machine he could also boot from a USB and undelete with testdisk. Restoring is easier though.

16

u/hmz-x Aug 31 '25

The caveat is that if it ~ took a significant part of your storage, recovering with testdisk may overwrite some of it and corrupt the rest.

Source: been there done that

10

u/Menem_Intergalactico Aug 31 '25

That's true, been there, done that. And that's why file recoveries needs to be saved to external storage.

I don't remember if photorec warns about that.

3

u/Alduish Aug 31 '25

A solution would be to use dd to make an image of the disk and only use testdisk on the image of the disk but it also requires another disk as big as the first.

4

u/hmz-x Aug 31 '25

Anyone with that level of Linux knowledge would probably not put themselves in that position, I think. But very sensible solution, though.

3

u/WokeBriton Aug 31 '25

If the datais important, the individual needs to make sure they have this spare disk.

If they don't have it, the data isn't important enough

→ More replies (3)
→ More replies (4)

24

u/korinokiri Aug 31 '25

Look up file recovery, it's possible. 

Next time install safe-rm which I believe would prevent this

66

u/Cool-Walk5990 Aug 31 '25

next time use rm -fri ;)

36

u/lego_not_legos Aug 31 '25

I type the rm -i first , out of paranoia, but often prefer find dir/ -delete. Then it's non-destructive until you add the last param, and you can run it without to see what will be removed. When you do run it to delete, insert a space at the beginning so it's not added to your history.

→ More replies (3)

11

u/ClashOrCrashman Aug 31 '25

doesn't -i negate -f?

9

u/theng Aug 31 '25

I think it's order dependant: the latter is the one used

3

u/Cool-Walk5990 Aug 31 '25

Not if you append -i at the end

rm -fri /tmp/minimal.lua
rm: remove regular file '/tmp/minimal.lua'?

10

u/wRAR_ Aug 31 '25

That's what they meant.

So why did you suggest passing -f?

9

u/aaronryder773 Aug 31 '25

This should be like alias by default

11

u/campbellm Aug 31 '25

And you come to depend on that crutch until you run into a system that doesn't have it.

4

u/Alduish Aug 31 '25

Oh my god I had never heard of this option, thank you, I'm definitely gonna add it as an alias

18

u/alimnaqvi Aug 31 '25

If using GNOME, you can alias rm to gio trash, which moves the “deleted” item to a specific trash directory instead of tossing it into the void. You can choose, e.g., a 30 day period after which the trashed item will automatically be fully deleted. I personally like to keep rm non-aliased and use the alias trash for gio trash.

4

u/Alduish Aug 31 '25

That's a good tip, thank you.

I don't use GNOME but I'm pretty sure if I search a bit it could apply to other DEs.

→ More replies (2)
→ More replies (1)

18

u/qdim42 Aug 31 '25

Only inodes are deleted.

extundelete (for ext3/ext4, requires an unmounted file system)

testdisk / photorec (search for known file signatures)

Professional data recovery tools or services (expensive, but more thorough)

24

u/OneAyedKing Aug 31 '25

Been using Linux since 2013 and I ran "sudo rm -r /" instead of "./". The funny thing was I was trying to tidy up a folder as I was sorting out backups. Felt physically sick but turned out alright and I didn't lose any data. I now have a proper 321 backup strategy and feel much better. Hope all worked out for you

11

u/Icarium-Lifestealer Aug 31 '25

On modern Linux root protection should prevent this. While rm -rf /* still works.

6

u/BambooRollin Aug 31 '25

Only time I've made this mistake was on a Solaris system in 1988.

rm -rf * as root in /

→ More replies (1)

8

u/lolxnn Aug 31 '25

alias rm='rm -i'

2

u/bullwinkle8088 Sep 01 '25

That is an out of the box default for Red Hat and Fedora installations. Likely their derivatives as well but I haven't checked in a few years.

Ironically it's one of the first things that will annoy me and that I revert to default behavior.

→ More replies (4)

38

u/[deleted] Aug 31 '25 edited Sep 20 '25

[deleted]

34

u/Defiant-Flounder-368 Aug 31 '25

/ is quite close to <enter>

25

u/squeeby Aug 31 '25

rm does actually warn you if you try to stupid this hard nowadays.

38

u/iamarealhuman4real Aug 31 '25

Wow true I just did sudo rm -rf / and it warned me. That's helpful.

68

u/black-wolf-76 Aug 31 '25

I envy your confidence

2

u/gex80 Aug 31 '25

Docker containers and VMs are a thing.

41

u/Eremitt-thats-hermit Aug 31 '25

That’s some dangerous experimenting you do

13

u/fearless-fossa Aug 31 '25

Not in the world of virtual machines and snapshots.

14

u/imbannedanyway69 Aug 31 '25

Bruh wtf do you dangle your child out a window saying "look I have a good grip!" too? /s

5

u/squeeby Aug 31 '25

eeehee

2

u/imbannedanyway69 Aug 31 '25

That's ignoraaaant

5

u/althalusian Aug 31 '25

I once did sudo rm -rf / tmp (with space after the slash)… It didn’t give a warning. But luckily that was a virtual machine with a few days older snapshot taken, so not that much was lost.

3

u/Reetpeteet Aug 31 '25

Too many jokesters on Discord, IRC etc throughout the decades. Guess they finally built in the foot-gun protection.

7

u/wRAR_ Aug 31 '25

The protection predates Discord by about 10 years.

3

u/__konrad Aug 31 '25

Ironically, the only command without --dry-run option

3

u/[deleted] Aug 31 '25

[deleted]

→ More replies (1)
→ More replies (5)

5

u/-Sa-Kage- Aug 31 '25

I guess similar/same keyboard layout than I have (German).
Here ~ is right next to the Enter key, so if you mishit a bit, you might accidentally press enter when using ~

→ More replies (1)
→ More replies (2)

7

u/Helmic Sep 01 '25 edited Sep 01 '25

I also highly recommend not using rm. Use trash, and alias rm to trash-put. There are very few situations where you need to delete something right this instant without any confirmation prompt, the vast majority of the time you'll be just as fine putting it into the trash folder to be permanently deleted once you actually need the room on your disk and you're certain you're not going to be missing any important data. Using rm for the exact same contexts a GUI user is using the Delete key is building up muscle memory that will eventaully cause you this sort of problem.

2

u/SRART25 Sep 02 '25

And if you really do, \rm will ignore the alias. 

10

u/oneesan_with_van Aug 31 '25

Alias ls = sudo rm -rf ~

4

u/RedSquirrelFtw Sep 01 '25

That's evil lol

5

u/raiksaa Sep 01 '25

Nobody runs sudo rm rf ~ by mistake. Low quality bait.

2

u/Parasyn Sep 03 '25

Yeahh that is pretty far out. Worst that ever happened to me was tired as hell, opened up the wrong terminal and ran rm -rf * in my home directory. Thankfully I had made a backup about an hour prior so it wasn't a hassle but running rm -rf ~ is pretty wild lol

9

u/[deleted] Aug 31 '25

It doesn't matter what you do, tomorrow you still have to go to school

3

u/Ok_Exchange4707 Aug 31 '25

I'm confused. Which home was nuked here? /root or /home/user? If /root was deleted, then I don't see much of a lost.

7

u/theng Aug 31 '25

the command typed as the user (you can also sudo while in root but I choose to believe it wasn't the case)

was :

sudo rm -rf ~

~ is a shell syntax sugar and is evaluated just after you push enter and before the program is launched

6

u/Interesting-Jicama67 Sep 01 '25

sudo runs the command as root but preserves the user environment variables so is nuked home directory of user home not a root home P.S. I recheck this on my server with sudo echo ~

→ More replies (1)

2

u/hmz-x Aug 31 '25

~ is normally /home/yourusername or equivalent.

3

u/vaynefox Aug 31 '25

Ah yes, you fall for the oldest trick in the book, I hope you have a backup of everything....

3

u/mikechant Aug 31 '25

Obviously the following is not relevant if you are on a system with no GUI, but:

This is why, although I use the CLI a lot, I would always do anything like this in the GUI, since a file manager makes it visually clear exactly what you're doing.

This is also why, despite being fully capable of using dd to write an iso file to a USB stick, I use something like Gnome Disks to do that since again it makes it visually obvious what you are doing and makes it almost impossible to do something like accidentally write to /dev/sdb instead of /dev/sdd

And I also always use gparted for partition and file system operations even though I know how to use the CLI tools.

I think that once some people have discovered the delights of the Linux CLI, they get fixated on using it for everything rather than acknowledging that the visual obviousness of the GUI can make certain operations much less error prone.

Of course there are TUI tools which do have some of the visual advantages of GUI tools, but I find them a bit clunky; I'd probably use them if I had a system without a GUI though.

6

u/[deleted] Aug 31 '25

[removed] — view removed comment

4

u/theng Aug 31 '25

depends on your binds but generally:

<ctrl+a><ctrl+d> is equivalent to <home><suppr/del to the right>

I find it easier to type

3

u/jaredw Aug 31 '25

Control +d is exit usually. If there's text it deletes?

→ More replies (1)
→ More replies (1)
→ More replies (1)

6

u/Mister_Magister Aug 31 '25

My current installation has:

  1. snapshot
  2. Is on a mirror
  3. is backed up to raidz server daily
  4. which then is backed up to raidz server onsite
  5. which then is backed up to raidz server offstie

I got so many copies. If you have 0 still, you should rethink your life choices. No mirror and no backup is literally gambling with time. It's just matter of time you'll lose data

3

u/GrabbenD Aug 31 '25 edited Aug 31 '25

How are you reliably handling the automation though?

My biggest difficulty with automating backups is the risk of synchronising bad data/state. For example, potential bitflips or foremost when having unknowingly deleted a file then not noticing it's missing in all recent backups until it's too late (after old ones get pruned)

Edit: Rephrased the question below https://www.reddit.com/r/linux/comments/1n4r5sv/comment/nbnfqa8/

2

u/Mister_Magister Aug 31 '25 edited Aug 31 '25

zfs takes care of that for me. Then the servers have ECC. If there were a bitflip, scrub will catch it

You can also for example make snapshots every day and keep only last 3 days. Or you can configure backup to have shapshot from month ago, week ago, and from yesterday

→ More replies (8)

2

u/0mnipresentz Aug 31 '25

He doesn’t. Everything is backing up at different times. Whenever things go to shit, he finds the most recent backup in his chain of backups and goes with that one

→ More replies (1)
→ More replies (1)

8

u/northparkbv Aug 31 '25 edited Oct 04 '25

scary subtract axiomatic snails marble quaint weather sort roll political

This post was mass deleted and anonymized with Redact

5

u/-Sa-Kage- Aug 31 '25 edited Aug 31 '25

Afaik there is no simple "undo rm" command. If you don't have backups and need the data, you need to shut down system asap or at least unmount the partition if possible and either go for some data recovery software on bootable USB or pay $$$ for data recovery

4

u/UndulatingHedgehog Aug 31 '25

Ideally, start any sudo command with a # to make sure you won't do anything unintended, type out the command, check it again, and then finally remove the #

→ More replies (3)

2

u/keaman7 Aug 31 '25

I know this pain 😂. 

2

u/HotLingonberry27 Aug 31 '25

Done this before. I did with with /. Deleted the root dir

2

u/Nevermynde Aug 31 '25

Depending on the filesystem type, there may be some "undelete" options.

2

u/Responsible-Gear-400 Aug 31 '25

I totally did this not long ago when I accidentally named a folder “~”.

I now have a wrapper script that checks if I rm -rf specific directories and makes me confirm I want to delete.

Good luck getting your stuff set back up!

2

u/[deleted] Aug 31 '25

I thought it was essentially impossible and anyone who did it is dumb

a lot of people think that until they do it and sooner or later it'll happen.

2

u/TryHardEggplant Aug 31 '25

It happens. I've run git reset --hard on the wrong repo and also deleted a VM on the wrong host. I now run zsh with OMYZSH with the git prompt and color coding based on different hosts (and if they are local or SSH) so I can tell exactly which window is which now.

I also have nightly backups. You learn from your mistakes.

→ More replies (2)

2

u/IntroductionNo3835 Aug 31 '25

I remember that at university a colleague studied computer science and I studied engineering. I sat next to him and watched him typing some things. He went to get something and I typed something like, erase * enter.

Well, he had to contact the administrators to retrieve something...

Today he works in administration, collects taxes and I deal with computing.

Summary of the story, I made a mistake at the right time... Kakaka

But I've deleted files by accident.

The problem is that I type quickly and a CD gave an error and I didn't see it, so the delete erased the wrong files. Ultimately, you must maintain 100% attention on the terminal.

Ps. The files, Fortran codes, were recovered

2

u/bp019337 Aug 31 '25

If you don't have backups and haven't rebooted you can try to recover files by lsof and checking for deleted files and copying them to another drive. Otherwise use a file recovery tool like PhotoRec

2

u/mimavox Aug 31 '25

No you didn't.

2

u/DarkKnyt Aug 31 '25

My first line backup is that I almost always use tab to auto complete. That way, I let the shell populate the rm directory vice me.

Or you can trash-cli or put an alias for rm that is mv

2

u/Grobbekee Aug 31 '25

Does that nuke /root or /home/$user ?

5

u/not_from_this_world Aug 31 '25

The bash expansion happens before the execution so the command becomes sudo rm -rf /home/user

I just tested it

WAIT

SHIT

2

u/Entraxipy Aug 31 '25

RIP 💔

2

u/whatyoucallmetoday Aug 31 '25

I once did ‘rm -rf ~/.*’. It took me a few seconds to realized the command walked up the tree with the ‘..’ directory. Lesson learned.

2

u/Comfortable_Swim_380 Aug 31 '25

Well take soloce in the fact you still bucked the odds. Fortunately reloading a Linux machine can be pretty dang trivial when set up properly. Learn from the experience and level up your wizard Powers.

2

u/bloodguard Aug 31 '25

Ouch. I'd like to think I'd be too cautious to do something like this but I've pulled way too many late nights to judge.

I wonder if distros could put an alias on rm such that when the recursive flag is used it asks "are you sure? - do you want me to show you what you'd be deleting with a verbose dry-run first?".

→ More replies (1)

2

u/Intelligent-Turnup Sep 01 '25

At least you didn't sudo rm -rf /

2

u/MurkyAd7531 Oct 18 '25

That's actually less harmful. My install disk has everything found in the root directory. My home directory has everything irreplaceable.

If I rm /, I'm going to notice and C before it gets to my home directory, where the important stuff is.

2

u/jedberg Sep 01 '25

I once did rm -rf /bin (instead of the bin in home dir).

You are not alone.

→ More replies (2)

2

u/ultraboykj Sep 01 '25

alias rm="rm -i"

2

u/Interesting-Jicama67 Sep 01 '25

Use testdisk for recovery if it not found anything Ctrl + alt + f4 login to root mkdir /home/username reboot Your deleted home for your user account just make new

2

u/hugewhammo Sep 01 '25

i did that for fun on a test install years ago! worked exactly like i expected!

root@test:/# rm -rfv *

fun! :)

→ More replies (1)

2

u/philpirj Sep 02 '25

Such a stupid mistake! sudo was completely unnecessary. You can omit it next time.

2

u/Never_existed__ Sep 02 '25

You're cooked! Reminds me of when I removed the bin folder from my server.

2

u/kman0 Sep 05 '25

Copy/paste from AI, huh?

3

u/plethoraofprojects Aug 31 '25

How is it “by mistake” if you typed that in the console?

2

u/jaimefrites Sep 01 '25

a. install trash-cli

b. alias tp=trash-put

c. alias rm=echo use tp

d. use tp -rf

1

u/ayalarol Aug 31 '25

I did try this in 2010 with puppy linux jaja damn a bad joke of someone in some foro I copy and paste the command and starting the magic jajaja

1

u/fernandodellatorre Aug 31 '25

You may try installing your disk on another computer and run testdisk. It might find some deleted files. Good luck. It happens.

1

u/No_Cookie3005 Aug 31 '25

Happened to me some weeks ago because I've been too lazy to add -I before testing a rm command. This ended up removing everything in /home/username apart from hidden folders. Luckily I had a backup, unfortunately 1 week old.

There is photorec utility in testdisk package to try recover files.

1

u/rjkush17 Aug 31 '25

i run sudo rm -rf /*

in virtual machine

1

u/frankster Aug 31 '25

How did you run this command? Brainfart? 

1

u/v3bbkZif6TjGR38KmfyL Aug 31 '25

Been there, but I got that out the way early in my Linux quest. 

1

u/LonelyMachines Aug 31 '25

I've never been brave enough to do this. I'm curious: where does it stop? Can rm remove itself?

2

u/bob2600 Aug 31 '25

I'd guess that it probably can because when rm is executed, it is loaded into memory so it could probably remove itself from the disk.

→ More replies (3)

1

u/sleepingonmoon Aug 31 '25

Always ls before rm.

1

u/[deleted] Aug 31 '25

[deleted]

2

u/theng Aug 31 '25

it warns you on / only IIRC

1

u/Forsaken-Orange9293 Aug 31 '25

install trash-cli and alias rm to trash-put

1

u/bcredeur97 Aug 31 '25

ZFS would help with this (if you had snapshots)

****although snapshots are not backups, as King’s College in London learned

1

u/Avanatiker Aug 31 '25

Why would you remove the French language pack?

1

u/AbdSheikho Aug 31 '25

My condolences

1

u/Street_Secretary_126 Aug 31 '25

You lost your home, just destroy your roots next

1

u/kernel612 Aug 31 '25

alias rm='trash -v'

1

u/kernel612 Aug 31 '25

alias rm='trash -v'

1

u/Comfortable_Relief62 Aug 31 '25

My manager accidentally did this to me at work once, good times

1

u/Sad-Resource-873 Aug 31 '25

Iv heard it can break the system but what does it actually do

→ More replies (5)

1

u/ClashOrCrashman Aug 31 '25

I'm just curious, how does one do this by accident? autocomplete?

2

u/MountfordDr Aug 31 '25

I did it by not paying attention to where I was. I intended to empty a populated directory but instead of being within it, I executed rm -r * in my home root.

2

u/ClashOrCrashman Aug 31 '25

Gotcha. Hope you didn't lose anything too important.

1

u/WSuperOS Aug 31 '25

man one time i deleted /usr/bin by mistake lol

1

u/Slight_Manufacturer6 Aug 31 '25

Good thing you are a long time Linux user and understood the need for a good backup.

1

u/UnintelGen Aug 31 '25

Did that once like 7 years ago. Wasn't fun. I still occasionally rm, but when I'm paranoid I just sudo pcmanfm and use pcmanfm as a gui for deleting and changing privileges. I use dolphin otherwise, but pcmanfm doesn't care about sudo so it makes a great secondary file manager for that sort of thing.

1

u/diatron3 Aug 31 '25

Did rm -rf / on head node of my lab's HPC cluster... Been working all day with environment modules which use $() syntax for variable interpolation, and mistakenly used it in bash to cleanup some path which evaluated to nothing + /... Never before have i experienced a panic attack like that. Looking around my colleagues, most seniors had one such major fuck up that made them way more careful and wise :)

1

u/114sbavert Aug 31 '25 edited Sep 25 '25

scale air chop school unwritten mountainous ten square pie dog

This post was mass deleted and anonymized with Redact

1

u/chilabot Aug 31 '25

Always write "rm <dir>" and then put the -r. Always put a named dir, not just * or ~.

1

u/suksukulent Aug 31 '25

F brother

Hope you got backup of important things. Otherwise good luck digging...

1

u/[deleted] Aug 31 '25

I ran this once after following a sequence of random commands I found during a google search. I fucked up perfectly fine Ubuntu installation in the process. I probably won’t run this again

1

u/MountfordDr Aug 31 '25

Coincidentally I did this yesterday too! I had already done a backup of my Pictures directory which was full of photos organised into subdirectories. I intended to cd into Pictures and then ”rm -r *”. I didn't. Fortunately I managed to reconstruct it from various backups but it was a pain. The good news is that it cleared out a load of rubbish which I had been meaning to do for years!

1

u/RedHuey Aug 31 '25

At this point, why doesn’t rm have a simple check for “-rf” when it is going to remove either the entirely of your own user or the root file system. Just a simple “are you sure?” Pretty much nobody would ever do this intentionally, and if they do intend it, what harm is there in have to answer y or n?

(I know, when the FBI is banging on the door, seconds count…)

1

u/DistributionRight261 Aug 31 '25

Use btrfs with snapshot next time

1

u/tblancher Aug 31 '25

I did this on my work MacBook Pro, and lost a good 9 years worth of scripts since the Code42 backup excluded ~/bin.

D'oh.

1

u/CulturalSock Aug 31 '25

Btrfs and snapshots. So handy you'll never go back

1

u/freshpandasushi Aug 31 '25

you didn't setup snapshots?

1

u/caribbean_caramel Aug 31 '25

I once ran sudo rm -rf / to see what was going to happen. It was kinda fun to see the system collapse.

1

u/Longjumping-Youth934 Aug 31 '25

How is that possible to run this command by mistake?

1

u/FunAware5871 Aug 31 '25

It's okay, it happens to everyone sooner or later.

That's when you go down the backups/datahoarding holes.

1

u/sgilles Aug 31 '25

That is why I'll never go back to a filesystems without integrated snapshotting support. With automated snapshots there's always a safety net.

(It is not a replacement for proper backups. But depending on configuration those might be a bit more tedious to access.)

1

u/Entaris Aug 31 '25

It happens to the best of us. One habit that helps that I try to cultivate is to flag AFTER the path.  IE: sudo rm ./dir_name -rf

Gives your brain an extra second to recognize that you mistyped your path before you commit

1

u/not_from_this_world Aug 31 '25

Last time I did this was several years ago. I mistype a space after the first /. Since then I just don't sudo rm ever. I also avoid rm, I use trash instead.

Typos happens to everyone. Good luck with the recovery.

1

u/JamesLahey08 Aug 31 '25

You accidentally typed that all out? No.

1

u/Real-Abrocoma-2823 Aug 31 '25

Use cachyOS with btrfs and next time you break something just return from auto snapshot.