By Linux Learner Beginner-friendly · Command line essentials

Linux Bash Command Line Tutorial for Beginners

A practical, no-nonsense guide to the Bash shell. Learn how to navigate the filesystem, manage files, use pipes, write simple scripts, and feel at home in the terminal.

Welcome. If you have ever opened a terminal and felt a little lost, this page is for you. Bash is the default shell on most Linux systems and macOS (and available everywhere else). Mastering a handful of commands unlocks real power: automation, remote work, debugging, and understanding how your system actually works.

We will stay practical. Every section shows real commands you can type right away. Copy them, change them, break things safely in a test folder, and learn by doing.

1. Getting started

Open a terminal. On Ubuntu and many desktops: Ctrl+Alt+T. On macOS open Terminal.app. You will see a prompt that often looks like:

username@hostname:~$

The ~ means your home directory. The $ (or sometimes % / #) means the shell is ready for input. Type a command and press Enter.

Tip: Use Tab for auto-completion of file and command names. Use the up/down arrows to recall previous commands. These two habits alone save hours.

Knowing where you are and how to move is the foundation of every Linux session.

Where am I?

pwd

pwd prints the current working directory (print working directory).

List contents

ls
ls -l
ls -la
ls -lh
  • ls — simple list
  • -l — long format (permissions, size, date)
  • -a — show hidden files (names starting with .)
  • -h — human-readable sizes

Change directory

cd Documents
cd ..
cd ~
cd /
cd -
  • cd dirname — enter a folder
  • cd .. — go up one level
  • cd ~ or just cd — jump home
  • cd / — root of the filesystem
  • cd - — previous directory

3. Working with files & directories

Create

mkdir projects
mkdir -p deep/nested/folder
touch notes.txt
touch file1.txt file2.txt

mkdir -p creates parent directories as needed. touch creates empty files (or updates timestamps).

Copy, move, rename

cp notes.txt notes-backup.txt
cp -r projects projects-copy
mv notes.txt Documents/
mv oldname.txt newname.txt

cp -r copies directories recursively. mv both moves and renames.

Remove (be careful)

rm notes-backup.txt
rm -r empty-folder
rm -ri projects-copy
Warning: There is no Trash in the classic command line. rm -rf is powerful and irreversible. Prefer -i (interactive) while learning, and never run destructive commands you copied from the internet without understanding them.

4. Viewing and editing text

Quick view

cat notes.txt
less /etc/hosts
head -n 20 big.log
tail -n 50 big.log
tail -f /var/log/syslog
  • cat — dump whole file (fine for short files)
  • less — scrollable viewer (q to quit, / to search)
  • head / tail — first or last lines
  • tail -f — follow a growing log in real time

Simple editing

For beginners, nano is friendly:

nano notes.txt

Save with Ctrl+O, exit with Ctrl+X. Later you can learn vim or another editor; the important part is being able to change a config file when you need to.

5. Pipes & redirection

This is where the shell becomes magical. You connect small tools into pipelines.

Redirection

echo "Hello Linux" > hello.txt
echo "Another line" >> hello.txt
ls -l > listing.txt
command 2> errors.txt
command &> both.txt
  • > — overwrite stdout to a file
  • >> — append
  • 2> — redirect stderr
  • &> — both stdout and stderr

Pipes

ls -la | less
ps aux | grep bash
cat access.log | grep 404 | wc -l
history | tail -n 30

The | character sends the output of the left command into the input of the right one. Combine grep, sort, uniq, wc, cut, and awk and you can answer almost any text-processing question.

6. Variables & the environment

name="Linux Learner"
echo "Hello, $name"
echo "Home is $HOME"
echo "Path is $PATH"
export MY_PROJECT=/home/$USER/projects
echo $MY_PROJECT

Use double quotes when you want expansion ($var). Single quotes keep text literal. export makes a variable available to child processes. Check current environment with env or printenv.

Tip: Put lasting customizations in ~/.bashrc (or ~/.bash_profile / ~/.profile depending on your system). After editing, run source ~/.bashrc.

7. Your first Bash scripts

A script is just a text file of commands. Create one:

nano hello.sh

Contents:

#!/bin/bash
# A tiny greeting script
echo "Hello from Bash!"
echo "Today is $(date)"
echo "You are: $USER"
echo "Working directory: $(pwd)"

Make it executable and run it:

chmod +x hello.sh
./hello.sh

The first line (#!/bin/bash) is the shebang — it tells the system which interpreter to use.

Simple logic

#!/bin/bash
if [ -d "$HOME/projects" ]; then
  echo "projects folder exists"
else
  mkdir -p "$HOME/projects"
  echo "created projects folder"
fi

for f in *.txt; do
  echo "Found: $f"
done

Test conditions with [ ] or the newer [[ ]]. Always quote variables that might contain spaces. Start small, add set -euo pipefail later for safer scripts, and keep learning.

8. Useful tips & next steps

  • man pagesman ls, man bash. Press q to quit. Also try ls --help.
  • historyhistory, then !42 to re-run a numbered command, or Ctrl+R for reverse search.
  • aliases — add to ~/.bashrc: alias ll='ls -lah' then source ~/.bashrc.
  • permissionschmod, chown, and understanding rwx will save you later.
  • find & locatefind . -name "*.log", find . -type f -mtime -1.
  • practice safely — create a playground directory and experiment there.

When you feel comfortable with the basics above, explore: SSH and remote servers, package managers (apt, dnf, pacman), systemd, and writing more robust scripts with functions and argument parsing.

The command line rewards curiosity. Type something, read the error, try again. That loop is how every Linux user improves.

Happy hacking — and welcome to the terminal.