function::discard - Linux


Overview

function::discard is a utility command used to discard the data and reclaim the space occupied by a block storage device, such as a hard disk drive (HDD) or solid-state drive (SSD). It is typically used on devices that need to be wiped or securely erased, ensuring that sensitive data is permanently removed and cannot be recovered.

Syntax

function::discard [options] <device>

– Specifies the block storage device to discard data from.

Options/Flags

-f, –force – Forces the operation to continue even if the device is mounted or in use.

-v, –verbose – Displays detailed output during the discarding process.

-s, –size – Specifies the amount of data to discard from the device. If not specified, the entire device will be discarded. The size can be specified in bytes, kilobytes (K), megabytes (M), gigabytes (G), or terabytes (T).

-p, –percent – Specifies the percentage of the device’s capacity to discard. The percentage must be between 1 and 100.

-w, –wipe – Performs a secure wipe of the device, overwriting all data with random bits multiple times. This option is more secure but slower than the default discard operation.

Examples

To discard the entire data on a device:

function::discard /dev/sda

To discard the first 100GB of data on a device:

function::discard -s 100G /dev/sda

To discard 50% of the device’s capacity:

function::discard -p 50% /dev/sda

To securely wipe a device:

function::discard -w /dev/sda

Common Issues

  • Device not found: Ensure that the specified device is connected and correctly identified.

  • Permission denied: Verify that you have sufficient permissions to perform the operation. Use sudo if necessary.

  • Device is mounted: Unmount the device before discarding its data. Use the umount command.

Integration

function::discard can be integrated with other commands to automate wiping or discarding operations. For example:

Wipe a device after it is unmounted:

umount /dev/sda && function::discard -w /dev/sda

Discard a specific amount of data from multiple devices:

find /dev/disk -type b -print0 | xargs -0 -L 1 -n 1 -P 4 function::discard -s 1G

Related Commands

  • hdparm – Controls and reports IDE/SATA hard disk drive parameters.
  • fdisk – Partitions a storage device.
  • dd – Copies and converts files.