Partitions

2 snippets across 2 stacks - Bash & Linux, SQL

Also written as partition by

SHBash & Linux

List Block Devices

SH · System Info
Syntax
lsblk [options]
Example
lsblk -f
Output
NAME   FSTYPE  LABEL   SIZE MOUNTPOINT
sda                    100G
├─sda1 ext4   root     50G /
├─sda2 swap            4G  [SWAP]
└─sda3 xfs    data    46G  /data

Note -f shows filesystem type, label, UUID, and mount points. Useful for identifying disks before mounting or partitioning. Linux only; on macOS, use diskutil list.

SQLSQL

PARTITION BY

SQL · Window Functions
Syntax
window_function() OVER (PARTITION BY column ORDER BY column)
Example
SELECT
  department_id,
  first_name,
  salary,
  ROW_NUMBER() OVER (
    PARTITION BY department_id
    ORDER BY salary DESC
  ) AS dept_rank
FROM employees;
Output
-- department_id | first_name | salary | dept_rank
-- 1             | Alice      | 95000  | 1
-- 1             | Bob        | 82000  | 2
-- 2             | Carol      | 105000 | 1
-- 2             | Dave       | 78000  | 2

Note PARTITION BY divides rows into groups and applies the window function independently within each group. It is like GROUP BY but without collapsing rows. You can partition by multiple columns.

Frequently asked questions

How does Bash & Linux handle partitions?
This task is covered in 2 stacks on this page: Bash & Linux, SQL. The "List Block Devices" snippet in Bash & Linux uses `lsblk [options]`.
Which command does the Bash & Linux example use?
The "List Block Devices" snippet uses `lsblk [options]`, from the System Info section of the Bash & Linux cheat sheet.
Which stacks cover "partitions" on this page?
Bash & Linux, SQL. Together they hold 2 copy-ready snippets for this task.
Is there anything to watch out for?
Yes. For "List Block Devices": -f shows filesystem type, label, UUID, and mount points. Useful for identifying disks before mounting or partitioning. Linux only; on macOS, use diskutil list.