In case you are wondering why a fork bomb works the way it works (since you said it looks like gibberish), it's deliberately designed to obfuscate how it operates. It's actually quite easy to understand though, if we replace ":" with a variable such as "x" it becomes a little more clear because ":" is just a function name. Adding some spacing helps to understand it too. So the whole fork bomb rewritten in more lines would be x( ) { x | x& }; x And now this actually looks a lot more legible. Basically we declare that the function "x" should be equal to itself piped into function "x" but open in the background (that's what "&" means in shell code). After declaring what we want it to do we run "x". That's literally all there is to this.
One thing I would like to point out is that I don't see much difference in using the ampersand sign (&) or not. In both cases it worked just as explosive. In theory it should give you less control when using the ampersand, because the processes are started disconnected from the current shell, but in practice the number of forks is so high that pressing Ctrl+C or closing my terminal window to kill the processes did not terminate the forks anyway. I use Zhs, maybe I should retry using Bash?
Just add "set -o noclobber" to your .bashrc, and that will deny the overwriting with ">", and just work for new files. If you want to overwrite, then you should use ">|"
I can easily imagine some malicious actor on a forum slipping in an echo > "some legit looking text" /dev/sda or rm -rf /* in a long copy-paste script as root after using su - no way someone new picks that up inside a wall of text. Thank god for moderators. Thanks for bringing attention to this potential hazard.
@Watcher actually there are legit reasons to run that, pretty sure I ran that (or an analogous command) while setting up drive encryption with sedutil and also while setting up FDE with OpenBSD
@@JungleLibrary Oh cool, proud I actually knew something I’m fairly “new” to Linux only been using for like a year currently in fedora but I’m working on a Gentoo install its pretty rough
I remember having a bash homework assignment once to recursively delete everything in the current directory, and all subdirectories in our school vms. Some classmate tested her script to make sure that it worked, but was on her home directory. She proceeded to delete all of her previous homework assignments and notes for the class.
Unless I missed it, I would like to see a video on your backup philosophy. Lately I've been having a lot of problems with timestamp and would love your input on various ways to avoid catastrophe.
I used the rm -rf command all the time as a linux system administrator. Just need double check you are using the correct path. It come in handy when need remove directory and all files inside.
So true in the terminal. However, the average Linux user today would probably use a file manager to remove a folder. Ignorance and no backups are the biggest issues here as I see it.
* First command is called "fork bomb" and wikipedia has an article about it. * These days on modern machines it's much harder to destroy your main drives with dd by accident and the reason for that is NVME. My main partitions are located at something like /dev/nvme0p1. USB drvies are /dev/sda. It's impossible to mistype, like it was with /dev/sda vs /dev/hda. I still use `fdisk /dev/sda` before writing to check that it's the disk that I want to overwrite. I like dd as I don't need to install balenaetcher/rufus for iso. * Personally, I was bit by bash glob mechanism. I once ran `chown -R me:me .*` in top level directory after distro reinstalling to change ownership of all configs and who knew: bash includes .. in this pattern. Oops. With recurison enabled it went into ../dev which at that time was usual collection of files, not fs populated at run-time. My distro was beyond repair.
Yeah, bash makes it hard to work with hidden files using wildcards. I've long since learned from others mistakes to use find or ls to acquire a list of files, examine it carefully with less and only once I've confirmed no files are included that I don't want included will I issue a command on it.
Ever heard of the meme: alias cd='rm-rf' Very dangerous for a new user to loose all its data without realising why. Because this is a famous meme, i was hoping you could inform people to never run this command 🙂
Not to mention all of the possible variants of that command. Videos like this one are nothing more than bandages that are minimally effective at best. People who refuse to learn the terminal should never use it. The real danger is choosing ignorance.
@@donaldmickunas8552 This can be summarised in a reformulation of Hanlon's Razor that I can easily see being much stronger than its original statement: _"Do not accuse something of being unnecessarily complex when such an accusation can be adequately explained by ignorance on your behalf, laziness on your behalf, or information you had not properly accounted for."_
@@donaldmickunas8552 I guess what I was trying to get at is that there are situations where I think things have been overly simplified. At times, there are things that really are more complicated than they need to be, often leading to inefficiencies, and in those cases you can rightfully accuse it as such as long as you know what you are talking about. But there are other times where I think things are too simple. In a lot of those cases it seems to me like that simplification was done solely out of laziness as I can't find legitimate enough reasons for it.
@@electric7487 While laziness may be a reason, I think that may be an over-simplification. Human beings are amazingly complex creatures. We are a combination of genetics, chemical reactions, beliefs, hopes, fears, memories and more. Why a single individual does anything may well be far more complex than the individual is aware of. Generally, people don’t like mysteries. So, they attach a reason to it that seems the most sensible from the impressions they have. It is astonishing how often such reasons are proven to be wrong. There is an old adage, “Don’t judge a book by its cover”. Consider the common idea that most if not all homeless people are drug addicts, alcoholics, or lazy bums. While there is some truth to this, spending time talking with these people opens one’s eyes to how a sequence of events, out of the individuals control, can result in one becoming homeless. Studies have shown that getting off the streets permanently without significant help is extremely difficult. Some of the most brilliant, wealthy people appear to be rather poor based on how they dress and act in general. If we are honest, most of us don’t truly know why we do the things that we do despite what we tell others.
@@donaldmickunas8552 why learn the hard way when the easy way is enough for you I mean imagine getting for example 1 year of work gone because of messing around with commands
I killed a server by performing rm -f from the root directory (you don't need the *). Thankfully I had a backup and restored the system fairly quickly. I created and alias called rm which aliased to rm -i to prevent that from happening again.
Okay I have to confess, I have been on different reddit groups and may have suggested to someone to run the infamous "rm -rf" command on their system, but in my defense I've always left a disclaimer in parenthesis stating that it was a joke and DO NOT run that command lol. Great work, Matt!
I'm not here to judge or condemn you, but sometimes people will go step by step, line by line, and may see your suggestion for command, enter the command, THEN look below it where the "it's a joke, don't do it" disclaimer is.
Pro tip: Do full filesystem backups (example. Rsync. Remember to keep X Attributes and use --sparse option if you have sparse files. Don't run a command you don't understand. If you want to delete a nvme use nvme-cli or simelar tool. You can't override ssd's.
2:59 Nah, bad advice. I have tried it a few times in QEMU / KVM, using Konsole on a KDE desktop and I can simply reboot the VM cleanly. I would always try to reboot a pc cleany as far as I can before risking to damage my system with the hard reset. Another thing: edit your shell history file afterwards to remove the entered line of code from history, in order not to risk unintentionally reusing it. 7:06 You cannot use sudo for echo because echo is a shell built in command. That is why you really need to start another shell as root and run echo from there.
i've been deleting everything on linux with "sudo rm -rf", on windows with "shift+del" for all my life. i haven't deleted anything accidentally, not once, never. i don't know how someone can accidentally types a command or presses a key combination on keyboard. the chance of that happening must be microscopically small.
Do you touch type or hunt and peck? I suspect you hunt and peck while looking at the keyboard. Touch typing increases speed as well as mistakes. Either that or your clams at a perfect record are false.
@@donaldmickunas8552No, i'm very fast on the keyboard. Not record breaking fast but i can bet i'm faster than 90% of keyboard users. But it's true that i don't constantly touch the keyboard. I don't peck but i only touch when i start typing, then pull my hands when i'm done. I don't leave my hands on keyboard idle. But i edit my posts after i post 10 times at least. I constantly add or substract words :) not a native english speaker. Even if someone leaves his hands on keyboard all the time, he can't still type "rm -rf" by accident. It has hyphen in it c'mon. Plus, he had to type the name of the file correctly by accident, too. Chances are too slim.
@@denizkendirci I deliberately pause and look at what I just wrote whenever I use rm, so I don't delete things on accident no matter how fast I type. *But* it's very easy for someone to be careless and make a typing mistake, especially if they're going at break neck speed.
@@anon_y_mousse true, i'm not saying that people don't or can't make mistakes, i'm just saying i don't understand how, because i've never experienced it for 28-30 years or so.
Phones are much more locked down than the average Linux Distribution. Try it on your home computer running Linux and see what happens. Besides, a small variation of the first one could make it very dangerous indeed. Obfuscation is a great way to hide all kinds of malicious code.
Accidents do happen. Work with computers long enough and something will trash part or all of a system. Yet, the vast majority of users have no backups. “That won’t happen to me.” Is delusional. Backups are vital! Cell phones are computers. People have irreplaceable data and photos on their phones without a backup. Photos, texts, passwords, etc. Then the phone stops working and panic sets in. The need to backup everything has been preached practically since the beginning. Despite this, foolish people ignore this message. This is my biggest rant.
@@synen yes it sure does, I started using it maybe 5 years ago. You can get an addon from the Microsoft website or get the functionality through control panel in add/remove software and it'll get it through windows update
Hey, I use Linux Windows 11 and I think the commands are different, what distribution does your Linux run on? Can you make an updated video for Linux Windows 11?
This is a Linux channel not a Windows channel. I doubt you will find a single video on how to do anything in Windows. I haven’t touched Windows since Windows 10 came out. Find a channel that focuses on Powershell and look for your answer there.
Remember to keep Hanlon's Razor in mind when writing a comment: _"Never attribute [an act] to malice [if it can be] adequately explained by stupidity."_
Want more Linux content from me? Follow me on Twitter! twitter.com/thelinuxcast
In case you are wondering why a fork bomb works the way it works (since you said it looks like gibberish), it's deliberately designed to obfuscate how it operates. It's actually quite easy to understand though,
if we replace ":" with a variable such as "x" it becomes a little more clear because ":" is just a function name. Adding some spacing helps to understand it too.
So the whole fork bomb rewritten in more lines would be
x( ) {
x | x&
};
x
And now this actually looks a lot more legible. Basically we declare that the function "x" should be equal to itself piped into function "x" but open in the background (that's what "&" means in shell code). After declaring what we want it to do we run "x". That's literally all there is to this.
One thing I would like to point out is that I don't see much difference in using the ampersand sign (&) or not. In both cases it worked just as explosive.
In theory it should give you less control when using the ampersand, because the processes are started disconnected from the current shell, but in practice the number of forks is so high that pressing Ctrl+C or closing my terminal window to kill the processes did not terminate the forks anyway.
I use Zhs, maybe I should retry using Bash?
Just add "set -o noclobber" to your .bashrc, and that will deny the overwriting with ">", and just work for new files. If you want to overwrite, then you should use ">|"
Thanks
Normal students in online class: Sir please press ctrl + alt + delete
Legends: Sir please run the command sudo rm -rf /*
I can easily imagine some malicious actor on a forum slipping in an echo > "some legit looking text" /dev/sda or rm -rf /* in a long copy-paste script as root after using su - no way someone new picks that up inside a wall of text. Thank god for moderators. Thanks for bringing attention to this potential hazard.
There is a special place in hell for such individuals
@Watcher actually there are legit reasons to run that, pretty sure I ran that (or an analogous command) while setting up drive encryption with sedutil and also while setting up FDE with OpenBSD
Wouldn’t it be echo “some legit looking text” > /dev/sda Or do both work?
@@smolbirb4 you are 100% correct, I tend to delete/move around parts of sentences when editing, must have mucked it up then.
@@JungleLibrary Oh cool, proud I actually knew something I’m fairly “new” to Linux only been using for like a year currently in fedora but I’m working on a Gentoo install its pretty rough
I certainly didn't know about the first and cryptic-looking command. Thanks for this video and hoping for more of this.
I remember having a bash homework assignment once to recursively delete everything in the current directory, and all subdirectories in our school vms.
Some classmate tested her script to make sure that it worked, but was on her home directory. She proceeded to delete all of her previous homework assignments and notes for the class.
lol
@@gylotip8393 Yup, all of her work/notes for the semester, gone, just like that.XD
Did she survive the class?
You should make a few videos on how to recover from accidents like this.... how to troubleshoot issues, how to restore from backups, etc..
Unless I missed it, I would like to see a video on your backup philosophy. Lately I've been having a lot of problems with timestamp and would love your input on various ways to avoid catastrophe.
I use a script with rsync.
I used the rm -rf command all the time as a linux system administrator. Just need double check you are using the correct path. It come in handy when need remove directory and all files inside.
So true in the terminal. However, the average Linux user today would probably use a file manager to remove a folder. Ignorance and no backups are the biggest issues here as I see it.
sudo rm -rf /
EDIT: For the record, I didn't watch the video completely when writing this comment. I just knew this would be in ;-)
That fork thing was a trick that people used back in my university days.
* First command is called "fork bomb" and wikipedia has an article about it.
* These days on modern machines it's much harder to destroy your main drives with dd by accident and the reason for that is NVME.
My main partitions are located at something like /dev/nvme0p1. USB drvies are /dev/sda. It's impossible to mistype, like it was with /dev/sda vs /dev/hda.
I still use `fdisk /dev/sda` before writing to check that it's the disk that I want to overwrite. I like dd as I don't need to install balenaetcher/rufus for iso.
* Personally, I was bit by bash glob mechanism. I once ran `chown -R me:me .*` in top level directory after distro reinstalling to change ownership of all configs and who knew: bash includes .. in this pattern. Oops. With recurison enabled it went into ../dev which at that time was usual collection of files, not fs populated at run-time. My distro was beyond repair.
Yeah, bash makes it hard to work with hidden files using wildcards. I've long since learned from others mistakes to use find or ls to acquire a list of files, examine it carefully with less and only once I've confirmed no files are included that I don't want included will I issue a command on it.
Before running some aur file, it may be good idea to check theses commands embedded in the code, especially the last couple
top dangerous: sudo apt install gnome
Ever heard of the meme: alias cd='rm-rf'
Very dangerous for a new user to loose all its data without realising why. Because this is a famous meme, i was hoping you could inform people to never run this command 🙂
Not to mention all of the possible variants of that command. Videos like this one are nothing more than bandages that are minimally effective at best. People who refuse to learn the terminal should never use it. The real danger is choosing ignorance.
@@donaldmickunas8552 This can be summarised in a reformulation of Hanlon's Razor that I can easily see being much stronger than its original statement:
_"Do not accuse something of being unnecessarily complex when such an accusation can be adequately explained by ignorance on your behalf, laziness on your behalf, or information you had not properly accounted for."_
@@electric7487 In other words, there is no such thing as too complex according to your variation. Convenient if debatable.
@@donaldmickunas8552 I guess what I was trying to get at is that there are situations where I think things have been overly simplified.
At times, there are things that really are more complicated than they need to be, often leading to inefficiencies, and in those cases you can rightfully accuse it as such as long as you know what you are talking about.
But there are other times where I think things are too simple. In a lot of those cases it seems to me like that simplification was done solely out of laziness as I can't find legitimate enough reasons for it.
@@electric7487 While laziness may be a reason, I think that may be an over-simplification. Human beings are amazingly complex creatures. We are a combination of genetics, chemical reactions, beliefs, hopes, fears, memories and more. Why a single individual does anything may well be far more complex than the individual is aware of. Generally, people don’t like mysteries. So, they attach a reason to it that seems the most sensible from the impressions they have.
It is astonishing how often such reasons are proven to be wrong. There is an old adage, “Don’t judge a book by its cover”. Consider the common idea that most if not all homeless people are drug addicts, alcoholics, or lazy bums. While there is some truth to this, spending time talking with these people opens one’s eyes to how a sequence of events, out of the individuals control, can result in one becoming homeless. Studies have shown that getting off the streets permanently without significant help is extremely difficult.
Some of the most brilliant, wealthy people appear to be rather poor based on how they dress and act in general.
If we are honest, most of us don’t truly know why we do the things that we do despite what we tell others.
Yes. For this reason, I try to not give a new user sudo rights. Sometimes, people need to learn the hard way.
You’re being nice. I would suggest that the vast majority of people learn the hard way.
@@donaldmickunas8552 why learn the hard way when the easy way is enough for you
I mean imagine getting for example 1 year of work gone because of messing around with commands
@@DarkGladiator I totally agree. That is the rational, sensible perspective. Yet, it would seem that most people still end up learning the hard way.
I killed a server by performing rm -f from the root directory (you don't need the *). Thankfully I had a backup and restored the system fairly quickly. I created and alias called rm which aliased to rm -i to prevent that from happening again.
Okay I have to confess, I have been on different reddit groups and may have suggested to someone to run the infamous "rm -rf" command on their system, but in my defense I've always left a disclaimer in parenthesis stating that it was a joke and DO NOT run that command lol. Great work, Matt!
I'm not here to judge or condemn you, but sometimes people will go step by step, line by line, and may see your suggestion for command, enter the command, THEN look below it where the "it's a joke, don't do it" disclaimer is.
Pro tip:
Do full filesystem backups (example. Rsync. Remember to keep X Attributes and use --sparse option if you have sparse files.
Don't run a command you don't understand.
If you want to delete a nvme use nvme-cli or simelar tool. You can't override ssd's.
exactly shred command was made with Hard disks in mind... I've heard ssd thwarts when u use the shred command and it doesn't rlly work
2:59 Nah, bad advice. I have tried it a few times in QEMU / KVM, using Konsole on a KDE desktop and I can simply reboot the VM cleanly.
I would always try to reboot a pc cleany as far as I can before risking to damage my system with the hard reset.
Another thing: edit your shell history file afterwards to remove the entered line of code from history, in order not to risk unintentionally reusing it.
7:06 You cannot use sudo for echo because echo is a shell built in command. That is why you really need to start another shell as root and run echo from there.
I never knew there is a difference between >> and > . Thanks Matt, I'll be careful next time.
Yes > is to create or overwrite and >> is append.
RIP to all those fallen VMs. Matt is a VM murderer...
I knew you were about to cover rm -rf eventually! Since you did it, I should do it too!
You are a great Linux teacher
Although I like the CLI, I judge the quality of a distro by how little it relies on CLI. 💪😎
The rm -rf is a good “self destruct” command...if you’re in that position👍
dd is such a fun command
i've been deleting everything on linux with "sudo rm -rf", on windows with "shift+del" for all my life.
i haven't deleted anything accidentally, not once, never. i don't know how someone can accidentally types a command or presses a key combination on keyboard.
the chance of that happening must be microscopically small.
Do you touch type or hunt and peck? I suspect you hunt and peck while looking at the keyboard. Touch typing increases speed as well as mistakes. Either that or your clams at a perfect record are false.
@@donaldmickunas8552No, i'm very fast on the keyboard. Not record breaking fast but i can bet i'm faster than 90% of keyboard users. But it's true that i don't constantly touch the keyboard. I don't peck but i only touch when i start typing, then pull my hands when i'm done. I don't leave my hands on keyboard idle. But i edit my posts after i post 10 times at least. I constantly add or substract words :) not a native english speaker. Even if someone leaves his hands on keyboard all the time, he can't still type "rm -rf" by accident. It has hyphen in it c'mon. Plus, he had to type the name of the file correctly by accident, too. Chances are too slim.
@@denizkendirci I deliberately pause and look at what I just wrote whenever I use rm, so I don't delete things on accident no matter how fast I type. *But* it's very easy for someone to be careless and make a typing mistake, especially if they're going at break neck speed.
@@anon_y_mousse true, i'm not saying that people don't or can't make mistakes, i'm just saying i don't understand how, because i've never experienced it for 28-30 years or so.
Fedora soon to remove hardware video decoding (vaapi), and I switched recently ffs
Great Work Thank yoU
I just read the same thing in Itsfoss 😅
First one is least dangerous. I was running it on my phone few times as an example of recursion.
Phones are much more locked down than the average Linux Distribution. Try it on your home computer running Linux and see what happens. Besides, a small variation of the first one could make it very dangerous indeed. Obfuscation is a great way to hide all kinds of malicious code.
@@donaldmickunas8552 I did try it on PC. They behave the same: device freezes and reboot is only solution
Accidents do happen. Work with computers long enough and something will trash part or all of a system. Yet, the vast majority of users have no backups. “That won’t happen to me.” Is delusional. Backups are vital! Cell phones are computers. People have irreplaceable data and photos on their phones without a backup. Photos, texts, passwords, etc. Then the phone stops working and panic sets in. The need to backup everything has been preached practically since the beginning. Despite this, foolish people ignore this message. This is my biggest rant.
There is also shred
"shred" is not guaranteed to work on modern file systems since most modern filesystems don't overwrite data in-place on your drive.
But I want to remove root and download more ram!
I love the Linux command line. I am learning PowerShell for work. I really don't like. Linux is better, but business use Windows more.
Great news! Starting with windows 10, windows began to support bash scripting natively!
@@JungleLibrary Windows supports Bash in cmd or powershell windows?
@@synen yes it sure does, I started using it maybe 5 years ago. You can get an addon from the Microsoft website or get the functionality through control panel in add/remove software and it'll get it through windows update
Hey, I use Linux Windows 11 and I think the commands are different, what distribution does your Linux run on? Can you make an updated video for Linux Windows 11?
This is a Linux channel not a Windows channel. I doubt you will find a single video on how to do anything in Windows. I haven’t touched Windows since Windows 10 came out. Find a channel that focuses on Powershell and look for your answer there.
@@donaldmickunas8552 I think he was making a joke. Not a very good one, but given his name...
@@anon_y_mousse Perhaps, hard to tell.
Best thing to do in Windows 11 terminal, as admin:
del C:\ /f /s /q
I’m planning on getting into Linux by using Crome os native vm. Just like to thank you for getting me into Linux.
GVM.
Ridiculous video!
Unsubbed...
Bye
Cya 🤡
bye falisha
Remember to keep Hanlon's Razor in mind when writing a comment: _"Never attribute [an act] to malice [if it can be] adequately explained by stupidity."_