pwd: print working directory
The directory you are in right now is called the working directory (or current directory). pwd prints its full path:
pwdIn the terminal
student@vulntech:~$ pwd /home/student
ls: list
ls lists the working directory. Give it a path to list somewhere else:
ls
ls Documents
ls /In the terminal
student@vulntech:~$ ls Documents Music Pictures todo.txt student@vulntech:~$ ls Documents school work student@vulntech:~$ ls / bin dev home media opt root sbin sys usr boot etc lib mnt proc run srv tmp var
Reading ls -l
ls -lIn the terminal
student@vulntech:~$ ls -l total 2 drwxr-sr-x 4 student student 0 Oct 16 19:07 Documents drwxr-sr-x 2 student student 0 Oct 16 19:07 Music drwxr-sr-x 3 student student 0 Oct 16 19:07 Pictures -rw-r--r-- 1 student student 19 Oct 16 19:07 todo.txt
Each line is one item. Take todo.txt:
| Column | Example | Meaning |
|---|---|---|
| Type and permissions | -rw-r--r-- | The first character is the type: - file, d directory, l link. The rest are permissions (a later module) |
| Links | 1 | Number of links to it. You can ignore this for now |
| Owner | student | The user who owns it |
| Group | student | The group that owns it |
| Size | 19 | Size in bytes |
| Modified | Oct 16 12:30 | When it was last changed |
| Name | todo.txt | The name |
More useful ls options
| Command | Shows |
|---|---|
ls -a | All files, including hidden ones |
ls -lh | Long format with human-readable sizes (K, M, G) |
ls -lt | Long format, newest first |
ls -R | Recursively: every directory inside too |
ls -d */ | Only directories |
Sizes in bytes are hard to read for big files. Compare:
ls -l Pictures/2024
ls -lh Pictures/2024In the terminal
student@vulntech:~$ ls -l Pictures/2024 total 2301 -rw-r--r-- 1 student student 2355200 Oct 16 19:07 beach.jpg student@vulntech:~$ ls -lh Pictures/2024 total 2.3M -rw-r--r-- 1 student student 2.3M Oct 16 19:07 beach.jpg
ls -R shows a whole branch of the tree:
ls -R DocumentsIn the terminal
student@vulntech:~$ ls -R Documents Documents: school work Documents/school: maths.txt Documents/work: report.txt
For a nicer picture of a branch, use tree:
tree DocumentsIn the terminal
student@vulntech:~$ tree Documents Documents ├── school │ └── maths.txt └── work └── report.txt 3 directories, 2 files
Tip:
ls -lais one of the most typed commands on Linux: everything, with details.
Remember:
pwdtells you where you are.lsshows what's there;-lfor details,-afor hidden files,-hfor readable sizes.