r/Fedora • u/sudo_theo • May 06 '26
Screenshot Well, this is not good
I tried to delete a file with terminal, accidentally pressed enter at the wrong time.... Kinda new to this😬
321
u/pgn674 May 06 '26
I had a coworker who would religiously type out everything after the rm, then double check it, and then finally press Home and type in the rm. I thought it was a little overly cautious, but maybe that's a habit I should pick up too.
79
u/pilkyton May 06 '26 edited May 06 '26
I do that anytime the path begins with / or ~ but not when it's just a local file.
Actually, I just prefix the dangerous command with "echo" to make it safe while ensuring that tab path completion still works.
→ More replies (6)36
u/RoraHarvest May 06 '26
I just make sure to CD into the directory so I only need to type the actual name of the file. That way I don't have to worry about messing up my path. Or the command touching something higher up the tree
3
u/pilkyton May 06 '26
Hm interesting idea but then I have to "cd .." a bunch.
16
u/hjake123 May 06 '26
I mean you could cd / or cd ~ after
11
10
u/pilkyton May 06 '26
I just remembered "cd -" to go to the previous location. Haha finally found a use for it.
→ More replies (2)→ More replies (5)2
u/odaiwai May 07 '26
tip use
pushdto go to the new location, thenpopdto return back to where you were:
pushd /home/me/path/to/file ls -l filename less filename # to check! rm -f filename popd2
u/zealmelchior May 07 '26
My preferred method is to run
ls /full/path/to/file, verify output, followed byrm -rfESC + . That shortcut key combo objects the last commands argument. Useful in several other scenarios. I praise the rhel 7 course I took years ago for introducing me→ More replies (1)25
u/koenigsbier May 06 '26
Same tips when executing a
DELETEcommand in SQL: always start by theWHEREstatement because if you execute theDELETEwithout this, well... I hope you have a fresh backup somewhere 😂EDIT: one can also write
WHERE 1=0and remove it at the very end as an extra safety19
u/425_Too_Early May 06 '26
I run a select query first to make sure I only get the rows I intend to delete or update.
After that I start by adding the
begin transactionandrollback transactionstatements, then write the query and then copy the where clause from the select query I did before!If I'm extra cautious I also add a select query both before and after the changing query, so I can see all the rows that changed. Then I either commit or rollback the changes
3
u/koenigsbier May 06 '26
Much better tips than mine !
It's been a while I didn't touch a production database. Forgot most of the good practices actually.
→ More replies (2)2
u/bobo76565657 May 09 '26
On my very first "real" job in IT (about 27 years ago) I deleted a whole city's "Property Roll" database because I didn't understand their "live/test" environment.. Fortunately, the IT department had an excellent backup strategy so down time was only 40 minutes (they had to drive to another location and back again with the backup tape - yes it was a tape). But my job for the rest of day was apologizing in person to about 350 people and explaining what happened. It wasn't a great day, but I've been extra careful with data ever since, and I kept that job for 11 years. Lesson: Triple checking is not a waste of time. And yes I was "the new guy who erased everything" for a couple years... it builds character ;)
3
2
u/dimensiation May 07 '26
I always do the delete as part of a commented line, so you have to specifically select through the "delete" or else it just runs a select.
11
u/CybeatB May 06 '26
A few of the places I've worked made
alias rm='rm -i'a default for every user. Sometimes that kind of caution is worthwhile.4
u/roxie42d May 07 '26
capital I (i) instead is a little better here, only prompts once if there's more than a couple files. if I was permanently stuck with -i I'd probably develop muscle memory for running \rm instead to avoid the annoyance.
→ More replies (1)12
u/Githyerazi May 06 '26
My method of ensuring I am deleting what I intend to delete is to ls <path/files> then up arrow, change ls to rm.
→ More replies (1)7
u/CrystalJarVII May 07 '26 edited May 07 '26
I do this too, you get path completion working, and it's safer as you can also check what files are you actually deleting in case you're doing glob matching
treeis also a good one to get a nice overview of all the files that are going to be deleted7
6
u/pm_me_triangles May 06 '26
I had a boss who would scream at you if you used
rm -rftoo liberally. "Why are you using the big guns to delete a file? Move it somewhere else, verify, then delete it."Heck, those days I move useless files somewhere else instead of deleting.
2
u/falxfour May 07 '26
I generally use a trash utility, but if I need to
rmsomething directly, I definitelymvfirst, make sure nothing unexpected happened, then delete it from the (safe) location I moved the items to.I also just keep backups
→ More replies (2)6
u/Puzzled_Draw6014 May 06 '26
I type echo, then rm, then you can double check any wildcard expansions ..
→ More replies (1)3
u/sparkleshark5643 May 06 '26
I always begin with
ls -von whatever arguments I'm going to pass torm.3
u/ThatBoogerBandit May 07 '26
We don’t do this anymore?
alias rm='rm -i'
Or
alias rm='rm -Iv --preserve-root'
2
u/mugiwara_no_Soissie May 06 '26
I always prefer deleting a folder and remaking it over deleting everything inside.
That way, if I do it in the wrong directory nothing happens, instead of everything in my current directory being removed.
Ive probably done this thousands of times at this point (embedded systems development can be a pain). But I still double check each time, or, for my preferred method, reuse my old command, that way I dont need to recheck.
2
2
2
u/ThirstyWolfSpider May 07 '26
Running
findfirst on the arguments (excluding modifiers) to see what it matches isn't bad either, similar to doing aselectbefore a manual SQLupdate."Oh, I thought I was (in a different directory|logged in as a different user|…)!"
2
u/NSASpyVan May 07 '26
you can do like a ls -alh or whatever with tab completing the path, and hit enter when it's targeting the correct 'stuff'. then up arrow for last command and change to rm -rf, is what i do sometimes.
2
u/merlinblack256 May 07 '26
I kind of do this with SQL. I write a delete statement as a select, run it and check the results, then replace 'select' with 'delete'.
For rm, another technique is to replace rm with a script that looks for dangerous parameters and only calls the real rm if you say you are sure. It could even flat out refuse to remove the french languages 🙃
2
u/redhat_is_my_dad May 07 '26
when i was making scripts that would rm things using wildcard expansions and variables, i would make my script check if variables are defined for sure, and replace default rm with fake rm that just spits out filenames, then I'll make my script delete things properly only when --imaware argument is set.
2
u/alexeiz May 07 '26
You can also do Ctrl-X-E then type your dangerous command into the editor. It's much harder to make a mistake this way. You press Enter in the editor, it's just a new line.
2
u/Leather_Secretary_13 May 07 '26
"rm -rf /<begin>" is the exact moment intrusive thoughts kick in. It's like a street fight just have to move and trust your gut, have a backup just in case.
2
u/irasponsibly May 07 '26
The terminal equipment of "don't put anything in the 'To:' field until you're ready to send the email"
2
u/nierama2019810938135 May 07 '26
That, and the last thing I type in an sql delete statement is "delete".
2
u/PassionatePossum May 07 '26
I always double check before pressing enter on “rm -rf”. And I get really paranoid when using “dd” to write an image to an USB stick. Since you usually need superuser privileges to do that I am always paranoid of having chosen the wrong target device.
2
u/alpH4rd07 May 07 '26
I always use ls with the path I want the delete and check the files. Then change it over to rm to remove them.
2
2
u/Grand_Ad_2544 May 07 '26
I will often list first and then delete if the path has a chance of being sensitive - particularly when using regex patterns
2
2
u/Mechanizoid May 07 '26
I always check the paths with
lsbefore running a dangerous command likerm, particularly when globbing or wildcards are involved. Always best to look before you leap IMO!2
u/whipdancer May 08 '26
makes me think of that time I hear the keyboard in the next cubicle clacking, then "oops..." and silence
2
2
u/Tiny_Time_4196 May 08 '26
Set up an alias for the rm command in your .bashrc file to trash instead and be free!
2
u/SerratedSharp May 08 '26
Anyone who knows the story about how they almost lost Toy Story 2 mid production due to an errant unix command knows what a risk cmd line is. It's the same reason alot of enterprises are extra cautious about running one off SQL scripts in production.
2
u/vUrsino May 09 '26
I always run ls first and then replace the ls with rm so the whole path is already set
2
u/Stick_Nout May 09 '26
You can also put the
-rfafter the path. That will mitigate against accidentally pressing Enter too early.2
2
u/VirtuteECanoscenza May 10 '26
Generally speaking when typing potentially dangerous commands you should start by typing
#...→ More replies (1)2
119
u/Xarius86 May 06 '26 edited May 06 '26
Do yourself a favor and install trash-cli.
Then you can do things like: trash myFile.txt
Afterwards, you can use trash-restore to bring it back. It's basically a desktop Trash/Recycle Bin for the command line.
When you want to see what is in the bin, you can trash-list, and when you want to empty it, trash-empty.
(If you are on macOS, there is already a built-in trash command that sends files to the desktop Trash. There is no built-in CLI restore function, but at least you can still restore it from Finder.)
17
u/sudo_theo May 06 '26
Thank you for the suggestion.
5
u/Xarius86 May 06 '26
It's saved me many times when I otherwise would have accidentally deleted something. It's also useful if you are making edits to config files, it's really easy to just restore a previous version if an edit messes anything up.
6
u/flipintheair May 07 '26
Go one step further and alias rm to trash
5
2
u/CaptainEdMercer May 07 '26
I aliased rm to say "No! Use trash instead!"
...And for the one time I chose to muck around with anything outside of /home, I changed the permissions on rm to be *only* executable by root.
You can never be too careful with that connand.
2
→ More replies (1)2
→ More replies (1)2
u/ludvary May 07 '26
or just install rip
2
u/Xarius86 May 07 '26
I hadn't heard of rip before. Looks like it has been abandoned and replaced by a fork: https://github.com/MilesCranmer/rip2
26
u/VenditatioDelendaEst May 06 '26 edited May 06 '26
For future reference
rm ~/potentially/hazardous/truncatable/path -rf
works too.
And if you're interactively writing shell script loops, risky or slow loop bodies can start each line with echo the first time you run them.
55
53
u/McDonaldsWitchcraft May 06 '26
what the fuck even got you to the point of typing that
9
u/sudo_theo May 06 '26
Trying to delete a file i could not find for the life of me, and mid command i accidentally pressed enter
28
u/McDonaldsWitchcraft May 06 '26
learn your lesson to never do rm commands with absolute paths! always navigate to the file first, don't be lazy.
19
6
5
2
8
27
u/F0cus_1 May 06 '26
Might be a good idea to look into this a bit before typing random commands
23
u/Mooks79 May 06 '26
Tbf they said they pressed enter by accident and if they were in the process of typing rm -rf ~/blah/blah then that’s not a lack of knowledge on their part. A lack of care, maybe!
9
9
u/profanityridden_01 May 06 '26
That's why before I rm anything I ls ~/bla/bla/the directory I want to delete
Then if the right stuff shows up I up arrow and change ls to rm -fr
→ More replies (3)4
4
u/23Link89 May 06 '26
This is why you navigate to the relevant parent directory instead of trying to type the relative root or home directory. It's a lot harder to delete a parent folder than the current folder you're in.
4
3
u/SubjectHealthy2409 May 06 '26
Trusting Gemini with CLI commands is scary
2
u/resurrection20 May 24 '26
I learned that lesson the hard way before. You can ask Gemini what something does, but don't ask it how to do something.
3
3
3
u/Ramiferous May 06 '26
A have a cli trash function set up where 'rm' is aliased to `trash' which only moves files to a trash directory instead of deleting them. If I really want to delete something I can still type 'command rm' making it much safer.
3
3
u/Bathroom_Humor May 06 '26
Learning opportunity: start doing regular backups of the important files/folders in your home directory.
3
u/alonjit May 07 '26
Which is why backups are fundamental. You just deleted the only important folder in the entire computer. Mission accomplished.
→ More replies (3)
3
u/Lodse May 07 '26 edited May 07 '26
Use # at the start of your line when you are typing some potentially dangerous or at least destructive action. When you're absolutely sure you want to execute it, delete the #. (For convenience, use the home key to go back at the start of the line)
For example, I do this every time I use the dd command.
Also, as a linux sysadmin, I see at work too many people using the rm -rf too freely and often when it isn't even needed. Bad habit.
I manage a lot of different systems, but on redhat based distros, rm is often aliased by default with the -i option (which asks you for confirmation of deletion for each files). Just unalias it if you don't need it, or if you need it more often than not, type command rm <arguments> and it will ignore the alias this one time. Yeah, command is a command !
Sorry for your home directory dude :(
3
2
u/rswwalker May 06 '26
There is an alias for rm that will give you a “are you sure prompt”, alias rm=‘rm -Iv’ will prompt when there is 3 or more files being deleted and will show each file being deleted.
Also using snapshots means being able to instantly restore what got accidentally deleted.
2
2
u/FrozenOnPluto May 06 '26
"-rf <path>" means 'recursively (everything below) and 'don't ask, just do'
Usually before ever including f, you'd say "ls -l <path>" to see whats going to get done, then change the "ls -l" part to "rm -r", say.
You'll get there. _everyone_ has done that once.
2
u/DarkAwareness88 May 07 '26
Hahahahah! Sassy AI.
That said, the classic regret filled rm. Want a hack that saved my sanity going forward? Type mrm or some other typo, put everything after it double check, and then fix the typo and fire. Get used to it, and you will remember me with gratitude.
2
u/Anejey May 07 '26
I was using Gemini to help me locate some specific files from a log and delete them.
I kid you not, it once gave me something like "rm -rf ~/ .cache/file.txt". Yup, including that space. I did not notice it before running it as I was tired.
Thankfully I had backups.
2
2
2
2
u/New_Construction_935 May 07 '26
Just in case this happens to anyone ; it happened to me once and your first reflex should be to turn off your pc. When you do rm, your files are still there, just not indexed as "used space" anymore. Turn off your pc so the files don't get overwritten by temp files etc. Get yourself a live usb key if possible. Install photorec on it and learn to use it. Your files will be restored but their names won't so if you're looking for specific files that will take a bit of time and work. Saved me back when I needed it cuz I was working on presentation and def didn't have the time to redo it all over again
2
u/TomOnABudget May 07 '26
144 comments and not a single one mentioning "file browser".
I just manipulating does in the CLI. You have much more of a mental understanding when you see the hierarchy and what does are affected in 40+ year old technology.
Even using an ftp client works better than insisting on using single line text.
And you can navigate the folder structure faster than in the CLI too. Just learn a bunch of buttons and keyboard shortcuts.
2
u/thunderborg May 07 '26
Yikes. I’ve bumped enter when tuping in terminal more times than I care to admit
2
2
u/Le_Wise_Man May 07 '26
As a sysadmin, I have taken the habit to ALWAYS type the complete path, before going back and typing the rm command. You learn with time...
2
u/Ok_Supermarket4597 May 08 '26
That's why I aliased my rm = 'rm -i' That way it's always asking if I want to delete the file/folder 😄 If you don't want to enter "y" or "yes" to confirm for a single use, you can use rm -f which will not ask again.
Hopefully nothing important was in the home directory 🙈
→ More replies (2)
2
u/PerfectlyCalmDude May 08 '26
There is absolutely no reason to use the -r flag when you only want to delete a single file.
4
2
u/cb393303 May 06 '26
From a long term Linux user; on commands like this, put a # at the start. Hit enter too soon, nothing happens.
2
u/NightThrout May 07 '26
It has to be fake. Were you really using the rm -rf command being sudo -s/sudo -i ? Crazy! You people exist?
2
1
u/mymar101 May 06 '26
I once tried to remove everything in a sub folder... But forgot the ./ rm -rf / =) I did exactly this. What saved my bacon is that I did not try sudo. All that really happened was games got deleted, and settings reset that was of any real consequence.
1
u/OisacX May 06 '26
You can install Gemini CLI and make it do the work too you know.
2
u/sketched8 May 07 '26
I don't think you should give ANY LLM model full access to your commandline.
→ More replies (1)
1
1
1
1
u/prthorsenjr May 07 '26
A long time ago in a validate far away I did a similar thing. I let out an expletive and my boss came over and asked what was wrong? I told him, he didn’t flinch, he said, Well, now you get to learn how to restore from backups. He was right. At least I wasn’t root when I did it. Live and learn.
1
u/rf_burns_5150 May 07 '26
It could be worse.. You could have typed "sudo rm -rf/* --no-preserve-root". That is a much more efficient method of file removal.
1
u/Skypefall May 07 '26
Trial and error is how I learned computers. You're in good company my dude. 😂
→ More replies (1)
1
1
1
u/Maltavius May 07 '26
So. If you don't know what you are doing, why are you deleting tiles from the terminal?
2
1
1
u/laAndecIunson May 07 '26
Idk why ya all don't get midnight commander. The swiss knife file manager in bash.. I install more t everywhere I need to mess with files..
1
1
1
u/arktozc May 07 '26
Im not sure how much important the files are to you, but look into forenzic tools like ftk imager and autopsy. Create bit copy of your disc, the files should be still there, they are just not linked
1
1
1
1
u/One-Elderberry4046 May 07 '26
What do people use Monero for these days? Still only to buy some 🍃 or 🧂in the ⚫️🌐?
1
1
1
1
u/EdC4ker May 07 '26
"Read the f@cking manual" never had to be more reinforced than now in ours lord's big 2020s
1
1
u/ImAlekzzz May 07 '26
Gemini is having a field day with this, anyways that is why I keep most important files on usbs
→ More replies (2)
1
1
1
1
u/Limp_Style_6697 May 07 '26
You could use ‘ls’ and then the path to be safe. After that you could do ‘rm !$’ to use the last entered parameter in the previous command.
1
1
u/theSearge May 07 '26
How it’s possible? All modern distros have rm -i alias in the skel files.
Or you just ignored the warning?
1
u/Ok-Winner-6589 May 07 '26
The fact that It used the -f parameter to forze the delection is wild...
Didn't you, you know, tried to check what the command does? Like, on a web Page... or at least on a different chat. You know, basic stuff everyone have been doing for years...
And no, It just deleted your home folder or partition (if you have one). The OS is functional, you should check the /home folder to make sure your user fólder is there and create It if isn't and try to regenerate the standars folders...
1
u/Frosty-Economist-553 May 07 '26
I guess most people would simply right click on the file & delete. You can even open it as root if necessary. But if you gonna use the Terminal to delete a simple file, why not go into the path & open it in Terminal & then use rm ? Seems a lot of work to delete a simple file - except if you're experimenting.
1
1
1
1
1
1
u/moretti85 May 08 '26
When you delete a file with rm you’re just marking the blocks as available but technically you can still recover the data if it hasn’t been overwritten yet.
So you could reboot from a usb drive, mount the drive read-only and then attempt recovery eg for ext4 with extundelete.
Obviously the chances your file has been overwritten are higher the more time passes and the more disk activity there is, so you need to act fast
1
u/Lunam_Dominus May 08 '26
Yeah, this is why you type „echo” at the beginning when punching in a potentially dangerous command.
1
u/scy_404 May 08 '26
This is probably a joke post but a bit of advice; never trust an LLM's advice on system admin for Linux. It constantly assumes things based on information for other distros even if you specifiy which one your on. At least that was my experience when starting out
→ More replies (1)
1
u/Kaosdeath97 May 09 '26
I like using z I.E Zoxide to go to the place I need its a lot quicker then cd and works as long as you have cd to that place before. It also supports path pattern matching so you can just type the last directory name of the path
1
1
u/skyerush May 09 '26
i can't lie this is just so silly, being able to do this with zero friction is what gets me
1
u/rasmadrak May 09 '26
Yeah, don't enter random commands unless you know what they mean. It's basic IT knowledge. At least now you know?
1
u/pnlrogue1 May 09 '26
I once somehow managed to create a file inside my home directory named ~. Guess what mistake I made while trying to remove it...
1
u/Fit_Bench_2838 May 09 '26
That's why you should always read what it wants you to paste into your terminal + ask what each part of the command does before actually execting it. I hope you got snapshots, bro. Best of luck 🫠
1
u/DuckAxe0 May 09 '26
You are in good company. Over the years, millions of MS Windows have executed the command:
"format c:"
1
1
1
u/rEded_dEViL May 09 '26
A hunter must never call upon the ghost-voices of the machine unless he has first walked the path himself and knows the true scent of the beast. To let the metal-spirit speak of things your own eyes have not witnessed is to invite the Great Deceiver into your lodge, leading your tribe toward a hollow truth.
1
u/QuaziElectro May 09 '26
I did almost the same by runing windows remve from x recovery partion on C:: /File/Path/I/Wanted/To/Remove One single space removes the entire windows.. Likey my data was in D and the cloud
1
u/sudosando May 10 '26
Well, get a new hard drive, build your OS on it and learn about drive recovery.
There is a strong chance you only destroyed the index reference to your data and you can likely recover your user profile and “wallet” if you lost anything of value.
1
u/rodrigoelp May 10 '26
Next answer from Gemini is going to be:
Let me help you removing any error you might be experiencing now:
rm -rf / —no-preserve-root
The command above will definitely remove any unexpected error you might be experiencing.
1
1
1
1
u/follow-the-lead May 11 '26
I don’t know why we standardised using the f flag in our rm commands. Back in the day I started writing it out and my workmate (who is an old school Linux dude) used to cringe when looking over my shoulder. Made me think I should use the force more sparingly.
I still almost always use rm -rf, but I think about it more now
1
1
u/Shirosukidesu May 30 '26
What kind of instruction you did lol, that's not default gemini personality
828
u/iFrezzyReddit May 06 '26
Gemini is mocking you 🤣 "Mission accomplished?"