$linuxjunkies
>

The Linux Command Line for Absolute Beginners

Learn the Linux command line from scratch: what the shell is, how to navigate with cd/ls/pwd, manage files, and master your first essential commands.

BeginnerUbuntuDebianFedoraArch9 min readUpdated June 7, 2026

Before you start

  • A running Linux installation or live session (any major distro)
  • A terminal emulator (GNOME Terminal, Konsole, xterm, or similar)
  • A regular user account — root is not required for most of this guide

The command line feels intimidating the first time you see it — a blinking cursor and no obvious instructions. Once you understand what the shell actually is and learn a handful of commands, it becomes the fastest way to get things done on Linux. This guide walks you through the essentials: what the shell is, how to move around the filesystem, how to work with files, and a set of commands you will use every single day.

What Is the Shell?

The shell is a program that reads the commands you type, passes them to the Linux kernel, and prints the results back to you. The most common shell on modern Linux systems is Bash (Bourne Again SHell). You interact with it through a terminal emulator — apps like GNOME Terminal, Konsole, or Alacritty on a desktop, or a raw virtual console when there is no graphical environment at all.

When you open a terminal you will see a prompt that looks roughly like this:

user@hostname:~$

Everything before the $ tells you who you are, which machine you are on, and where in the filesystem you currently are (~ is shorthand for your home directory). The $ itself means you are a regular user. A # means you are root — the system administrator account. Be careful as root; there is no undo for most destructive commands.

Understanding the Linux Filesystem

Linux organises everything in a single tree rooted at / (called "root"). There are no drive letters like Windows uses. Key directories you will encounter immediately:

  • /home/yourname — your personal files, also written as ~
  • /etc — system-wide configuration files
  • /var — variable data: logs, spool files, caches
  • /tmp — temporary files, cleared on reboot
  • /usr/bin — most user-facing programs live here

Paths start with / (absolute) or a directory name / . (relative to where you currently are).

pwd — Print Working Directory

pwd tells you exactly where you are right now. Run it whenever you feel lost.

pwd

Output will look like /home/alice or wherever your current directory is.

ls — List Directory Contents

ls lists files and directories. On its own it shows the current directory.

ls

Add flags to get more useful output:

ls -l          # long format: permissions, owner, size, date
ls -lh         # same but human-readable sizes (KB, MB)
ls -la         # include hidden files (names starting with .)
ls /etc        # list a specific directory without changing to it

Hidden files (dotfiles) store configuration — .bashrc, .ssh, and so on. You will not see them unless you use -a.

cd — Change Directory

cd moves you from one directory to another.

cd /var/log        # go to an absolute path
cd Documents       # go to a subdirectory of the current directory
cd ..              # go up one level to the parent directory
cd ../..           # go up two levels
cd ~               # return to your home directory
cd -               # go back to the previous directory

cd - is underused and extremely handy — it toggles you between the last two directories you visited.

Working with Files and Directories

Creating Files and Directories

mkdir projects                  # create a directory
mkdir -p projects/web/css       # create nested directories in one step
touch notes.txt                 # create an empty file (or update its timestamp)

Viewing File Contents

cat notes.txt          # print entire file to the terminal
less /var/log/syslog   # scroll through a large file (q to quit, / to search)
head -20 notes.txt     # show first 20 lines
tail -20 notes.txt     # show last 20 lines
tail -f /var/log/syslog  # follow a file in real time (Ctrl+C to stop)

less is your go-to for anything longer than a screen. Use arrow keys or Page Up/Down to scroll, and /searchterm to find text.

Copying, Moving, and Renaming

cp notes.txt backup.txt              # copy a file
cp -r projects projects_backup       # copy a directory recursively
mv notes.txt documents/notes.txt     # move a file to another location
mv backup.txt archive.txt            # rename a file (mv does both)

Deleting Files and Directories

rm oldfile.txt              # delete a file
rm -i oldfile.txt           # ask for confirmation before deleting
rm -r old_project/          # delete a directory and everything in it

There is no Recycle Bin. rm is permanent. Use -i when you are not certain, and be especially careful with -r. Never run rm -rf / or rm -rf ~.

Five More Commands You Will Use Constantly

man — Read the Manual

man ls
man cp

Every standard command has a manual page. Press q to exit, / to search within it. When in doubt, read the man page before searching online.

grep — Search Inside Files

grep "error" /var/log/syslog          # find lines containing "error"
grep -i "error" /var/log/syslog       # case-insensitive
grep -r "TODO" ~/projects/            # search recursively in a directory

echo and Redirection

echo "Hello, Linux"                   # print text to the terminal
echo "first line" > output.txt        # write to a file (overwrites)
echo "second line" >> output.txt      # append to a file

The > and >> operators redirect output. The pipe operator | chains commands — the output of one becomes the input of the next:

ls -l /etc | less                     # browse a long directory listing
cat /var/log/syslog | grep "error" | tail -20

sudo — Run as Root

sudo apt update          # Debian/Ubuntu: update package lists
sudo dnf update          # Fedora/RHEL family
sudo pacman -Syu         # Arch

sudo runs a single command with root privileges. You will be asked for your own password (not root's). Use it only when necessary — installing packages, editing system config files, managing services.

history and Tab Completion

history          # show recent commands
!42              # re-run command number 42 from history
Ctrl+R           # reverse search through history (start typing to filter)

Press Tab once to auto-complete a command or filename. Press it twice if nothing happens — Bash will show you all matching options. Tab completion is one of the biggest productivity gains on the command line.

Verification: Put It Together

Try this short sequence to confirm everything is working and practise what you have learned:

pwd                                   # confirm your starting location
mkdir ~/cli_test && cd ~/cli_test     # create and enter a test directory
echo "line one" > test.txt
echo "line two" >> test.txt
cat test.txt                          # should show both lines
grep "two" test.txt                   # should return "line two"
cd ~                                  # return home
rm -r cli_test                        # clean up

Troubleshooting Common Beginner Problems

  • "command not found" — You mistyped the command, or the program is not installed. Check spelling first with man commandname or which commandname.
  • "Permission denied" — You do not have access to that file or directory. Either use sudo (if it is a system file) or check ownership with ls -l.
  • Terminal appears frozen — A command is running or waiting for input. Try Ctrl+C to cancel it, or Ctrl+D to send end-of-file.
  • Accidentally opened Vi or Nano — To exit Nano press Ctrl+X. To exit Vi/Vim type :q! and press Enter.
  • Long line of text with no prompt — You are inside less or another pager. Press q to quit.
tested on:Ubuntu 24.04Fedora 40Debian 12Arch 2024.05

Frequently asked questions

What is the difference between the terminal and the shell?
The terminal (or terminal emulator) is the window that displays text. The shell is the program running inside it that interprets your commands. GNOME Terminal is a terminal emulator; Bash is a shell.
How do I cancel a command that is running or stuck?
Press Ctrl+C to interrupt and stop most running commands. If a program is waiting for text input you can also press Ctrl+D to signal end-of-file.
Is it safe to use sudo for everything?
No. Sudo grants root-level power, which bypasses all file permission checks. Use it only for tasks that genuinely require it — installing software, editing system files, managing services. Routine file and directory work in your home directory never needs sudo.
How do I deal with filenames that have spaces in them?
Wrap the name in quotes (cd 'My Documents') or escape the space with a backslash (cd My\ Documents). Tab completion handles this automatically, so it is worth using Tab to complete filenames whenever possible.
What is the difference between > and >> when redirecting output?
The > operator creates the file if it does not exist and overwrites it if it does. The >> operator appends to the end of an existing file without destroying its current contents.

Related guides