DEV Community

Alexandre Plt
Alexandre Plt

Posted on

2 1

Deadly commands and why you should be extra careful with them

I'm writing this from my personal experience, because I broke a few systems by misusing some commands...

chown & chgrp

I wanted to save a server which wasn't booting because of a kernel update which went badly. Thus I put a FTP server on the rescue server, mounted the disk of the original server, and tried to retrieve the files. The FTP was launched as user, the partition mounted listed files from root, thus the FTP couldn't retrieve them.

My best (actually, the worst) idea? A chown -R user and a chgrp -R user... This affected the mounted partition but also the original files (which is logical but I didn't think about that).

We were able to downgrade the kernel version in the /boot partition and boot it again afterward but alas, it was unusable because everything was owned by user, even things like sudo or shutdown.

TL;DR When using chown and chgrp, be extra careful.

The usual one, rm

I have a friend who was trying to create a temporary website for an association, named "abc". Well, it wasn't a success thus he tried to delete it. The first time he typed the wrong name, the second time he forgot -r, the third there was an error and he needed to add -f as well.

The plot twist? There was another folder for another website named "pbn", and 3 times he typed "pbn" and not "abc". The wrong website was deleted, unrecoverable.

How it could have been avoided? By having alias rm='rm -i' in the .bash_aliases, asking for a confirmation to delete a file (for every file if -r was added). If you are sure and have reviewed it carefully, you can pipe the rm command with yes which will send "y" to every prompt from rm -i.

Conclusion

I'm hoping that I'll be able to add more commands to this article, without causing too much damage, and I also hope that this will help some of you!

Image of Datadog

The Future of AI, LLMs, and Observability on Google Cloud

Datadog sat down with Google’s Director of AI to discuss the current and future states of AI, ML, and LLMs on Google Cloud. Discover 7 key insights for technical leaders, covering everything from upskilling teams to observability best practices

Learn More

Top comments (3)

Collapse
 
freezmeinster profile image
Bramandityo Prabowo

Long time ago as Slackware user i accidentally wipe some important configuration file because of redirect command. I used single ">" instead of ">>"

Collapse
 
yellow1912 profile image
yellow1912

One time I accidentally wiped out my os with rm -rf.

Collapse
 
lexplt profile image
Alexandre Plt

Luckily that never happened to me (yet), but I'm afraid I'll forgot the . when I write rm -rf ./*

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Discover a treasure trove of wisdom within this insightful piece, highly respected in the nurturing DEV Community enviroment. Developers, whether novice or expert, are encouraged to participate and add to our shared knowledge basin.

A simple "thank you" can illuminate someone's day. Express your appreciation in the comments section!

On DEV, sharing ideas smoothens our journey and strengthens our community ties. Learn something useful? Offering a quick thanks to the author is deeply appreciated.

Okay