Linux Shell - Basics
Introduction
Section titled “Introduction”In this document, the basics of a Linux shell will be explained. There will also be some usefull basic command’s listed, so you can start using the Linux shell immediately.
Background
Section titled “Background”What is a Shell?
Section titled “What is a Shell?”A shell is the program that lets you interact with the operating system by typing commands. Bash (Bourne Again Shell) is the most common on Linux. The shell translates what you type into system calls that Linux understands.
The shell can run in different “modes”. For example, logging in through SSH starts a login shell, while opening a new terminal window in GNOME or KDE usually gives you a non-login shell. Understanding these differences matters because different startup files are read depending on the type of shell.
Note: Read Linux Shell - Scripting for more information about startup files.
What is TTY?
Section titled “What is TTY?”You’ll often see “tty” in Linux (for example /dev/tty1). TTY stands for teletypewriter. Back in the early days of UNIX, people interacted with big computers through physical terminals that worked like electric typewriters. Modern Linux still uses the word “tty” to mean “a terminal session.” Each virtual console (like pressing Ctrl+Alt+F3) is a different TTY.
So when we say login shell on a TTY, think: “a full user login, usually on a physical or SSH terminal.”
Startup Files
Section titled “Startup Files”Different files are loaded when you log in. They are simply shell scripts that set environment variables, define aliases, or configure prompts.
-
/etc/profile
System-wide config for all users. Runs once at login. Sets PATH, umask, and other global defaults. -
~/.profile
User-specific login file for POSIX shells. Works forsh,dash, and sometimes Bash. -
~/.bash_profile
Bash-specific login file. Commonly used to load environment variables. Most people configure it to also source.bashrc. -
~/.bashrc
Runs for every interactive non-login shell. This is where you normally put aliases, functions, and prompt tweaks.
How They Work Together
Section titled “How They Work Together”Typical setup:
export PATH=$PATH:$HOME/bin[[ -f ~/.bashrc ]] && . ~/.bashrcThis way, when you log in, .bash_profile ensures .bashrc is also loaded.
💡 Rule of thumb:
- Use
.bash_profilefor environment variables that you want to be available everywhere (e.g., PATH changes). - Use
.bashrcfor things like aliases, functions, and interactive tweaks.
Usefull command’s
Section titled “Usefull command’s”| Command | Description |
|---|---|
cp <source> <target> | Copy a file or directory |
cp -r <source> <target> | Copy recursively, including subdirectories |
mv <source> <target> | Move or rename a file/directory |
rm <target> | Remove (delete) a file |
rm -r <target> | Remove recursively, including subdirectories (DANGER!) |
touch <target> | Create an empty file |
mkdir <dir> | Create a new directory |
rmdir <dir> | Remove an empty directory |
grep <pattern> <file(s)> | Search for a pattern in file(s) Example: grep error /var/log/messages (Search for “error” in /var/log/messages) |
find <path> -name <name> | Find files by name starting from a path Example: find / -name "*.log" (Find all .log files starting from root) |