The Academy

Loading the search index…

Searches the academy on this device only.

Looking at the system: df, du, free, ps, top, whoami and id

Use seven read-only commands to see how full your disk is, how much memory is in use, which programs are running and which account you are using, and learn to read each result.

25 minelementaryUbuntu/LinuxPractical task needs a laptop or desktop

Marking a lesson as read does not prove you can do it. Skills count as demonstrated when you pass the quiz (not yet) and complete the practical tasks (not yet).

By the end of this lesson you will be able to

  • Read df -h and say how much space is used and available on the main disk.
  • Use du -sh to measure how big a folder is.
  • Read free -h and say how much memory is in use and available.
  • List processes with ps and top, and quit top safely.
  • Use whoami and id to say which account and groups you belong to.

When a computer feels slow or says it is full, the first step is to look, not to guess. In earlier lessons you used graphical tools such as System Monitor. The terminal has equivalents that work the same way on a laptop, a server in another country, or a computer with no screen. The commands below only report information. Reading their output calmly is the skill: each one answers a simple question about your machine.

Every command in this lesson is read-only. You can run any of them from any folder, but staying in ~/practice is a good habit. The numbers in the examples belong to a fictional laptop. Yours will be different, and that is expected.

How full is my disk? df and du

df (disk free) reports the space on each storage area the system knows about. Add -h for human-readable sizes (G for gigabytes, M for megabytes). Many lines belong to the system and can be ignored. The one that matters most for you is the line whose last column is /, the main disk, where your files live. A Mount point is the place in the folder tree where a disk or partition is attached; / is the root of everything.

Terminal (Linux) · you can run this on your own computer
df -h
Simulated interface: not a real screenshot

df -h on a fictional laptop: the line ending in / is the main disk (simulated).

amina@laptop: ~/practice (simulated)
  1. Marker 1: The main disk: 28% used, 161G free
  2. Marker 2: A small system partition; leave it alone
df -h on a fictional laptop: the line ending in / is the main disk (simulated).
Read this figure as text

A simulated terminal showing df -h output with columns Filesystem, Size, Used, Avail, Use percent and Mounted on.

A simulated bash terminal running df -h. The header is Filesystem, Size, Used, Avail, Use%, Mounted on. Marker 1 points to the line /dev/nvme0n1p2 with size 234G, used 62G, available 161G, use 28% and mounted on /. This is the main disk: 28 percent is used, so there is plenty of room. Marker 2 points to the line for /boot/efi, a small system partition of 511M. Other lines such as tmpfs are temporary memory-based areas that you can ignore.

df tells you about the whole disk. To find out what is using the space, du (disk usage) measures folders. -s gives one summary total instead of a line for every sub-folder, and -h makes it readable. Give it one or more folders.

Terminal (Linux) · you can run this on your own computer
du -sh ~/practice
du -sh ~/Documents ~/Pictures ~/Downloads
Text
28K     /home/amina/practice
12M     /home/amina/Documents
1.2G    /home/amina/Pictures
340M    /home/amina/Downloads

How much memory? free

free -h shows RAM (working memory) and swap. Swap is an area of disk the system can use as slow emergency memory when RAM runs short. The column that answers 'how much can new programs still use?' is available, not free. Linux deliberately fills spare RAM with cached data to speed things up, and gives it back instantly when a program needs it, so a small free number is normal and healthy.

Terminal (Linux) · you can run this on your own computer
free -h
Simulated interface: not a real screenshot

free -h: look at the available column first (simulated).

amina@laptop: ~/practice (simulated)
  1. Marker 1: available: memory new programs could still use
  2. Marker 2: Swap unused: memory is not under strain
free -h: look at the available column first (simulated).
Read this figure as text

A simulated terminal showing free -h output with memory and swap rows and columns total, used, free, shared, buff/cache and available.

A simulated bash terminal running free -h. The Mem row shows total 15Gi, used 3.1Gi, free 8.9Gi, shared 312Mi, buff/cache 3.4Gi and available 12Gi. Marker 1 points at the available value 12Gi, which is how much memory programs could still use. Marker 2 points at the Swap row: total 3.9Gi, used 0B, free 3.9Gi, so swap is not being used at all, a sign of a healthy system.

What is running? ps and top

A Process is a running program. ps prints a snapshot of processes. With no options it lists only those started from your current terminal, which is a short list: the shell itself and ps. Each has a PID, a unique number the system uses to refer to it. Adding aux lists every process for every user, which can be hundreds of lines, so pipe it into head as you learned: ps aux | head -n 5.

Terminal (Linux) · you can run this on your own computer
ps
ps aux | head -n 5

top is a live, refreshing version: it redraws every few seconds, with the busiest processes first. Read the top block for load and memory, and the table below for individual programs. Press `q` to quit. Pressing keys other than the documented ones may do nothing, so do not experiment with the options shown in its help screen until you have read about them.

Terminal (Linux) · you can run this on your own computer
top
Simulated interface: not a real screenshot

A shortened view of top: summary at the top, busiest programs below (simulated).

top (simulated, shortened)
  1. Marker 1: Time, uptime and load average
  2. Marker 2: How many processes exist and what they are doing
  3. Marker 3: id = idle: 95.6% of the CPU is doing nothing
  4. Marker 4: Memory in MiB
  5. Marker 5: One row per program, busiest first. Press q to quit
A shortened view of top: summary at the top, busiest programs below (simulated).
Read this figure as text

A simulated terminal showing the top command with a summary of tasks, CPU and memory, and a table of processes with PID, user, CPU and memory columns.

A simulated bash terminal running top. Marker 1: the first line gives the time, how long the computer has been up, and load average. Marker 2: the Tasks line says 281 total processes, 1 running, 280 sleeping. Marker 3: the %Cpu line shows 95.6 id, meaning 95.6 percent of the processor is idle. Marker 4: the MiB Mem line shows total, free, used and cache in mebibytes. Marker 5: the table lists processes with PID, USER, CPU percentage, memory percentage and COMMAND, for example gnome-shell with PID 1873 using 2.3 percent CPU and firefox with PID 3055 using 1.7 percent CPU. The learner presses q to leave.

Who am I? whoami and id

whoami prints the name of the account you are using. id adds the numbers and groups behind it: your user number (uid), your main group (gid) and every group you belong to. Groups decide what you are allowed to do. In the example below, the group sudo is the one that allows Amina to act as an administrator when she chooses to; a later lesson explains it.

Terminal (Linux) · you can run this on your own computer
whoami
id
Text
amina
uid=1000(amina) gid=1000(amina) groups=1000(amina),4(adm),24(cdrom),27(sudo),30(dip),46(plugdev),100(users),114(lpadmin)
Which command answers which question
QuestionCommandLook at
Is my disk nearly full?df -hThe / line: Use% and Avail
Which folder is the big one?du -sh folderThe size at the start of the line
Is memory running out?free -havailable, and whether Swap is used
What is running right now?ps, ps aux, topPID, %CPU, %MEM, COMMAND
Which account am I?whoami, idThe name, and the groups list

Common mistakes

  • ✖ Instead of: Panicking because the free memory number looks tiny.

    ✔ Do this: Read the available column. Linux uses spare RAM as a cache on purpose.

  • ✖ Instead of: Running du on / or on the whole disk.

    ✔ Do this: It scans every folder and can take a long time and print permission errors. Measure a specific folder instead.

  • ✖ Instead of: Trying to close top by closing the terminal tab in a hurry, or typing random keys.

    ✔ Do this: Press q. It quits cleanly and returns you to the prompt.

If something goes wrong

du prints 'Permission denied' lines.
You tried a folder you are not allowed to read, often one that belongs to the system. Stay within your own folders such as ~/Documents, or ignore those lines: they only mean that part could not be counted.
top fills the screen and nothing responds when I type a command.
top is still running. Press q (or Ctrl+C) and wait for the prompt to return.
df -h shows many lines I do not recognise.
That is normal. Linux lists several system areas. Look for the line whose Mounted on column is / and ignore the rest.

Key terms

Mount point
The place in the folder tree where a disk or partition is attached and becomes usable.
Swap space
Disk space the system uses as slow overflow when memory is full.
Process ID
The number, also called a PID, that identifies one running process.
Group
A named set of user accounts that can share permissions on files and tasks.

Practise it for real

Reading is not the same as being able to do it. Complete these on your own computer, then tick only what you have actually done. These ticks are your own honest record: nothing checks them for you.

Guided exerciseNeeds a laptop or desktop

Make a five-line health check of your laptop

On your Ubuntu laptop run df -h, du -sh ~/practice ~/Documents ~/Downloads, free -h, ps and id. Write five short sentences: the Use% of the / line, the largest of your three folders, the available memory, one PID shown by ps, and your user name with at least one group.

You have succeeded when:
Independent challengeNeeds a laptop or desktop

Challenge: read top and quit it

Run top. Without touching any other keys, identify the three busiest programs by %CPU and how much of the CPU is idle. Open a web browser, watch top change for ten seconds, then press q to leave top. Explain what changed.

You have succeeded when:

Knowledge check

7 questions. You need 80% to pass. Mistakes here are part of learning, and you can retry as often as you like.

  1. Question 1.You want to know how big your Downloads folder is. Which command fits?
  2. Question 2.A small number in the free column of free -h means your computer is almost out of memory.
  3. Question 3.Your df -h output has a line /dev/nvme0n1p2 234G 221G 1.2G 100% /.What does that tell you?
  4. Question 4.Match each command to the question it answers.
  5. Question 5.You started top and the screen keeps refreshing. How do you leave it?
  6. Question 6.Order a sensible, safe way to start investigating a slow computer from the terminal.
    1. Run free -h and check available memory
    2. Close the busy program normally from its own window
    3. Run df -h and check the / line
    4. Run top and look at the busiest programs
  7. Question 7.A PID is a number that identifies one running process.

Summary

  • df -h shows disk space; the line ending in / is your main disk.
  • du -sh folder tells you how big a folder is.
  • free -h shows memory; read the available column, and check whether swap is in use.
  • ps lists processes and top watches them live; press q to quit top.
  • whoami gives your account; id adds your numbers and groups.

Checklist: can you do these?

Marking a lesson as read does not prove you can do it. Skills count as demonstrated when you pass the quiz (not yet) and complete the practical tasks (not yet).

Related lessons

References and further reading

Official sources for details that can change between versions.

On this page