student@ubuntu:~$
unix-foundations Lesson 1 8 min read

Your First Commands

whoami, pwd, ls, cd, and the five-step process that runs every command you type

Reading: Shotts, The Linux Command Line: pp. 39–54

Quick check: Do you know what pwd prints? If yes, skip to What Happens When You Type a Command.

Practice this topic: Terminal Basics skill drill

After this lesson, you will be able to:

  • Run whoami, hostname, date, uname, cal, pwd, and ls
  • Use flags (-a, -l, -la) to modify command behavior
  • Explain the five-step process the shell uses to execute a command
  • Navigate directories with cd and read files with cat and head
  • Use man to look up any command’s documentation
  • Use history and shortcuts to recall previous commands

Six Commands to Start With

Open your terminal and type each of these:

whoami          # your username
hostname        # machine name
date            # current date and time
uname -a        # OS and kernel info
cal             # this month's calendar
pwd             # current working directory

Each command does one thing — that is the Unix philosophy: programs should do one job and do it well.

Flags Change Behavior

Most commands accept flags (short options starting with -):

ls              # list files in current directory
ls -a           # include hidden files (names starting with .)
ls -l           # long format (permissions, size, date)
ls -la          # both

If you know Java: ls -la /tmp is like calling ls.run("-la", "/tmp"). Flags are method arguments.

If you do not know Java: Flags are instructions that modify what the command does, like adjusting settings on a machine. -l says “show details.” -a says “include hidden files.” You can combine them: -la.

What Happens When You Type a Command

When you type ls and press Enter, five things happen:

  1. The shell reads your input
  2. The shell searches PATH for a program called ls. PATH is a list of folders where the shell looks for programs — when you type ls, it checks each folder in PATH until it finds one called ls.
  3. The shell asks the kernel (the core software that runs Linux) to create a new process
  4. The ls program writes to stdout (standard output — by default, your screen)
  5. The shell displays a new prompt

This is why ./hello requires the ./ — the shell only searches the folders listed in PATH, and the current directory is not in that list by default. You must tell the shell exactly where to look.

Exploring with ls

ls -l

Output looks like:

drwxr-xr-x  2 student student 4096 Mar 30 09:00 Documents
-rw-r--r--  1 student student   42 Mar 30 09:00 notes.txt
Column Meaning
d or - directory or file
rwxr-xr-x permissions (Week 2)
student student owner and group
4096 size in bytes
Mar 30 09:00 last modified
Documents name

Moving Around with cd

pwd tells you where you are. cd takes you somewhere else:

cd /etc            # go to the /etc directory (absolute path — starts with /)
pwd                # confirm: /etc
cd ~               # go back to your home directory
pwd                # confirm: /home/yourname
cd /var/log        # go to the system log directory
cd -               # go back to where you just were (toggles between two directories)

The key idea: absolute paths start with / and work from anywhere. They are like a full street address. You will learn about relative paths (shorter, context-dependent) in the next lesson.

Special shortcuts:

  • ~ means your home directory (/home/yourname)
  • .. means the parent directory (one level up)
  • - means “where I just was” (toggle)

Deep dive: File System Navigation — absolute vs relative paths, special directories, tab completion

Reading Files

You can look at file contents without opening an editor:

cat .bashrc        # print the entire file to your screen
head -10 .bashrc   # just the first 10 lines
less .bashrc       # scroll through a long file (press q to quit)

cat is fine for short files. For anything longer than a screen, use less — you can scroll with arrow keys, search with /, and quit with q.

Deep dive: Viewing File Contents — cat, head, tail, less, wc


Check Your Understanding
You type myprogram at the prompt and get "command not found." The file exists in your current directory. What is wrong?
AThe file is corrupted
BYou need to compile it first
CThe current directory is not in PATH — use ./myprogram
DYou need root permissions
Answer: C. The shell searches PATH for programs. The current directory (.) is not in PATH by default. You must specify the path explicitly: ./myprogram.

Getting Help with man

You will forget flags. That is normal. The manual is built in:

man ls              # open the manual page for ls

Inside man, press / to search, q to quit. It works like less.

man -k "copy files"  # search all man pages for a keyword

Deep dive: Manual Pages — man page sections, SYNOPSIS notation, --help vs man

Recalling Commands with history

The shell remembers every command you type:

history             # show numbered list of past commands

Shortcuts to save time:

!!                  # repeat the last command
!47                 # repeat command number 47
!ls                 # repeat the most recent command starting with "ls"

Press Ctrl+R to search your history interactively — type part of a command and it finds the match.

Your history is saved to ~/.bash_history between sessions, so you can recall commands from previous logins.

Deep dive: Command History!!, !n, Ctrl+R, security implications


What Comes Next

You can run commands, look up documentation, and recall what you’ve typed. Next: creating, moving, and organizing files and directories.