Table of contents
- Introduction
- Commands to avoid which can erase data
- Commands dangerous to the CPU and RAM
- Conclusion
Introduction
As system administrators and network engineers , we should be aware and avoid execution of some of the dangerous commands. These commands can cause significant impact to the system by producing irreparable damage or sometimes DOS attack. Since some of these commands are possible to execute accidentally , we should use caution while handling them
In this article we will cover in detail on some of them and how it can get accidentally executed on your system
Commands to avoid which can erase data
Redirection of file output directly to partition disk
The following command is very dangerous to execute as it erases the data on a disk and overwrites with other data. Usually /dev/sda or /dev/sdb
are disk partitions
cat test.txt > /dev/sdb
Executing such a command can be quite possible , if you do some mistakes like the following example ,
Where the file path we would like to redirect the contents of one file to another file is /dev/sdb/test2.txt
, but leaving space in between will make the file redirection of the cat test.txt to get first overwritten to the /dev/sdb
and erases the data on the hard disk
#Actual command planned to execute
cat test.txt > /dev/sdb/test2.txt
#But what we might have executed accidentally ( notice the space )
cat test.txt > /dev/sdb /test2.txt
Another possible variation of this problem is executing a command to redirect /dev/null
to a file accidentally executed against the disk partition ( notice the space )
cat /dev/null > /dev/sdb /test2.txt
Attempt to delete files on a directory ended up catastrophic
The following command is quite dangerous as it erases all the files and directories recursively
rm -rf /
Again this command is quite possible to get executed accidentally
Let’s say we were planning to execute the rm
command to delete a target directory and its files , But accidentally we added one extra space due to the typo
#Actual plan
rm -rf /mnt/media/test/
#But what accidentally got executed ( notice the space)
rm -rf / mnt/media/test
rm - removes files or directories if combined with -r
-r - recursively operate on recursive deletion of directories and files
-f - forcefully delete the files without confirmation
Executing a command without knowing the command’s use case
mkfs
command formats a disk and helps with forming new filesystem , executing the following command erases a disk and reformats it with the ext4 data storage format
mkfs.ext4 /dev/sdb
Commands dangerous to the CPU and RAM
Fork
:(){ :|:&};:
This command creates a function named “:”
and executes itself in foreground and background . it is one of the worst DOS attacks , where your system freezes. The only way to recover your system is by hard reboot by removing the power , as no commands can be executed
Piping output from the history to shell for executing the commands again
The following commands can help is pipe all the commands part of the history output to the shell execution again , awk is used to print the second column here as sometimes we can see the first column with the sequence numbers of the history command output
history | awk '{print $2}' | sh
Or
history | sh
This command when ran , will execute all the commands part of the history output and will cause significant CPU usage and if there were some dangerous command present , it can delete the files on a wrong directory
Conclusion
In this article we have covered some of the dangerous commands we should avoid executing on our linux systems or the linux systems we manage as some of them cause irreparable damage to the system. Knowing the consequences of these commands , helps us to express caution and mentor others on avoiding such a commands from getting executed
For more interesting articles like this , please visit the following link
https://discoveringsystems.com/category/linux/
Or our official website discoveringsystems.com