Skip to content

Linux Shell - Basics

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.

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.

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.”

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 for sh, 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.

Typical setup:

~/.bash_profile
export PATH=$PATH:$HOME/bin
[[ -f ~/.bashrc ]] && . ~/.bashrc

This way, when you log in, .bash_profile ensures .bashrc is also loaded.

💡 Rule of thumb:

  • Use .bash_profile for environment variables that you want to be available everywhere (e.g., PATH changes).
  • Use .bashrc for things like aliases, functions, and interactive tweaks.

CommandDescription
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)