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

Your First Commands

whoami, pwd, ls, 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

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 in action.

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

From Java: In Java, you passed arguments to methods. In Unix, you pass flags and arguments to commands. ls -la /tmp is like calling ls.run("-la", "/tmp").

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
  3. The shell asks the kernel to create a new process
  4. The ls program writes to stdout (your screen)
  5. The shell displays a new prompt

This is why ./hello requires the ./ — the shell only searches PATH directories, and . (the current directory) is not in PATH by default. You must tell it explicitly 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

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.

What Comes Next

You can run commands and read output. Next: creating, moving, and organizing files and directories.