The command-line interface is a powerful and handy tool for administering a Linux system. However, if you are not careful you can very quickly destroy <or> wreck havoc on what you have installed to your HDD or NVME, M.2 or SSD.
Trust me on this. By accident I've deleted my home directory before and crashed my desktop environment in the past.
In this article I'll touch on a handful of commands that should be used sparingly.
/dev/null
The /dev/null is a null device that discards any data that is written to it.
Moving a directory or file to /dev/null/ get's destroyed. In simpler terms, it vanishes for good!
The Remove Directory Command
rmdir (remove directory)
Using the command 'rmdir' works but if the directory is full running rmdir <name of dir> doesn't remove the directory. I created a directory and named it "Experiment"
Running 'rmdir Experiment' was not removed with root privileges because the directory had a file and a picture in it. Instead, I had to run the rmdir command with the -r flag.
Alex: sudo rm -r Experiment
Alex: ls
Desktop Downloads 'My Art Work' Packages Public Videos
Documents Music Notes Pictures Templates
Remember the directory’s location as this will remove the file(s) and you can’t undo it!
Permissions Commands
There are many permissions commands. Today I will cover 2 of them. The chmod and chown commands.
The chmod command is a command that modifies a file or directory’s read, write, and execute permissions. In Linux, each file is associated with three user classes – owner, group member, and others.
Here’s the basic syntax:
chmod [option] [permission] [file_name]
For example, the owner is currently the only one with full permissions to change note.txt. To allow group members and others to read, write, and execute the file, change it to the -rwxrwxrwx permission type, whose numeric value is 777:
chmod 777 note.txt
Linux is a multi-user system, and the chmod command allows you to change file permissions to configure user access to a certain file or directory.
However, chmod can recursively change the permissions of all your files.
Using CHMOD -R 777 /
chmod -R 777 /
The command above 'allows all users' to read, write, and execute all files on the system, which compromises security. Additionally, certain systems may malfunction if the permissions are too open and prevent the system from booting.
The Chown Command
The chown command lets you change the ownership of a file, directory, or symbolic link to a specified username.
Here's the basic format:
chown [option] owner[:group] file(s)
For example, if you want to make linuxuser2 the owner of filename.txt:
chown linuxuser2 filename.txt
The Kill Command
The kill command is used to terminate an unresponsive program manually. It will signal misbehaving applications and instruct them to close their processes.
I've used the kill command a hand full of times executing ps ux from a terminal and I've had success.
To kill a program, you must know its process identification number (PID). If you don’t know the PID, run the following command:
ps ux
After knowing what signal to use and the program’s PID, enter the following syntax:
kill [signal_option] pid
There are 64 signals that you can use, but these two are among the most commonly used:
SIGTERM requests a program to stop running and gives it some time to save all of its progress. The system will use this by default if you don’t specify the signal when entering the kill command.
SIGKILL forces programs to stop, and you will lose unsaved progress.
For example, the program’s PID is 63773, and you want to force it to stop:
kill SIGKILL 63773
KUDOS to : Valentinas Čirba who wrote this very helpful article:
40 Essential Linux Commands That Every User Should Know
******Be careful with /dev/sda as well. Or any path to any of your hard disk drives, M.2 or SSD's for that matter.******
Executing a command and appending it with >/dev/sda writes the command's output on the /dev/sda block, i.e., on your hard drive. The dev/sda block contains filesystem data, which is then replaced with the command output, damaging your system and making it irrecoverable.
(){ :|:& };: Fork Bomb
The fork bomb command creates a function called : and defines the contents of the function, making it execute itself and pipe into another call of itself. Thus, the function runs in the foreground while making the same process run in the background. The function executes and replicates itself repeatedly, quickly taking up all your resources until the system freezes.
The foo bar Command
The ^foo^bar command can be both useful and dangerous.
While the command saves time because it allows you to edit the command you ran previously and execute it again, it can also cause issues if you don't thoroughly check the changes you make before running it.
The Wget Command
The wget command allows you to download files in the terminal. However, the command may instruct wget to download a script from a malicious source and execute it with sh.
Always pay attention to the address of the package or file you are downloading, and make sure it is a trusted source, or else you risk infecting your system.
The History | SH Command
The history | sh command can be dangerous because it executes every command from the command log that you have already executed. The action can cause system instability and execute commands that you didn't want to execute again.
Use caution when using the history | sh command if your not sure look it up, seriously.
A gentlemen named: Bosko Marijan wrote this article so KUDUS to him!
14 Dangerous Linux Terminal Commands
Oh, and while I'm thinking of it.... Don't launch G-parted and remove any partitions without knowing exactly what is on the partition and what device it is on.
Over the years of participating in Linux Forums I've seen many people accidentally delete the wrong partition or partitions and had to perform fresh installations.
Enjoy your Linux and drive safe!
Alex
Good stuff, Alex. Well laid out, and highly informative.