# Cheatsheet & Examples: top

`top` is a command-line utility that provides a dynamic, real-time view of running processes in a Unix-like operating system. It displays information about CPU and memory usage, process IDs, and other system statistics, allowing users to monitor system performance and identify resource-intensive processes.

## Monitoring System Processes (Default View)

Example Usage:
`top`

What it does:
Displays a constantly updated, interactive view of running processes, sorted by CPU usage. This is the basic, no-frills way to invoke `top`.

Command-line Arguments Explained:

This basic usage doesn't include any arguments.

## Sorting by a Different Field

Example Usage:
`top -o %MEM`

What it does:
Displays processes sorted by memory usage (%MEM).

Command-line Arguments Explained:

- `-o %MEM`: Specifies the field to sort by. `%MEM` represents the percentage of memory usage. You can use other fields like `CPU` (CPU usage) or `PID` (process ID).

## Updating Delay

Example Usage:
`top -d 5`

What it does:
Updates the display every 5 seconds. The default update interval is typically 3 seconds.

Command-line Arguments Explained:

- `-d 5`: Sets the delay between screen updates to 5 seconds. The value is specified in seconds.

## Batch Mode

Example Usage:
`top -b -n 1`

What it does:
Runs `top` in batch mode, outputting the results to standard output and then exiting after a specified number of iterations (in this case, 1). This is useful for capturing a snapshot of system activity.

Command-line Arguments Explained:

- `-b`: Runs `top` in batch mode.
- `-n 1`: Specifies the number of iterations to run.  After the specified number of iterations, top exits.

## Filtering by User

Example Usage:
`top -u username`

What it does:
Displays only the processes owned by the specified username.

Command-line Arguments Explained:

- `-u username`: Filters the display to show processes owned by the user "username". Replace "username" with the actual username.

## Displaying Command Lines

Example Usage:
`top -c`

What it does:
Toggles the display of the full command lines for each process. This can be helpful to understand what arguments a process was run with.

Command-line Arguments Explained:

- `-c`: Toggles the display of the full command line.  Pressing 'c' while top is running will also achieve the same result.

## Highlighting

Example Usage:
`top -H`

What it does:
Highlights the current process being viewed with a different color.

Command-line Arguments Explained:

- `-H`: Highlights the current process being viewed with a different color.
