Your First Commands
whoami, pwd, ls, and the five-step process that runs every command you type
Quick check: Do you know what
pwdprints? 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, andls - 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 /tmpis like callingls.run("-la", "/tmp").
What Happens When You Type a Command
When you type ls and press Enter, five things happen:
- The shell reads your input
- The shell searches PATH for a program called
ls - The shell asks the kernel to create a new process
- The
lsprogram writes to stdout (your screen) - 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 |
myprogram at the prompt and get "command not found." The file exists in your current directory. What is wrong?.) 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.