How do I Completely Wipe My Hard Drive in Ubuntu?

“This tutorial explains how to fully wipe the hard drive in Ubuntu and Debian-based Linux distributions.

Usually, Linux users use the rm command to remove files and directories.

When we remove a file using the command rm, what we are really doing is labeling the removed file or directory as “rewritable space” on the disk.

Therefore the removed data can be restored if it wasn’t overwritten by another piece of data, as explained in previous articles on computer forensics and data recovery.

In this tutorial, 5 tools to carry out a full removal of data are explained: wipe, srm, dd, shred and scrub. All of them can be executed from live distributions to wipe a hard drive.

All instructions below include screenshots, making it easy for every Linux user to understand them.”

The Wipe Command

The wipe command allows us to fully erase data from our disk; it rewrites the sector and flushes the cache making it impossible or very difficult to retrieve the data.

To install wipe on Debian/Ubuntu, run:

sudo apt install wipe -y

The wipe command is useful for removing files, directories, partitions, or disks.

To remove a single file using wipe execute:


For example, to remove the file opera_autoupdate.log I run:

wipe opera_autoupdate.log

wipe -r

To remove a directory named zenmapinst/ I run:

wipe -r zenmapinst/

To wipe a partition or disk, speeding up the process, add the parameter -q,  execute:

wipe -q

In the following example, I will wipe the partition /dev/sdc2.

wipe -q /dev/sdc2

Wiping the Hard Drive Using SRM

The srm tool overwrites the data before deleting it; it is a similar option to wipe. To install srm on Debian or Ubuntu, run:

sudo apt install secure-delete

Similarly to rm, you can run:


For example, to remove a file named “ssl”, run the following command:

srm ssl

To remove a directory, add the flag –r using the following syntax.

srm -r

To remove a directory named “ytfzf”, use the following:

srm -r ytfzf

How to Wipe the Hard Drive With the dd Command

The dd command can be used to overwrite a disk. If you formatted a disk, you could run this command to fill the disk with random data, making it impossible to restore.

It overwrites the disk with zero and allows us to format the device in different formats. It comes by default on Debian and Ubuntu-based distributions.

In the following example, the dd command is used to fill the /dev/sdc device with random data.

dd if=/dev/urandom of=/dev/sdc bs=4k

The shred Command to Overwrite Files in Linux

Shred is another alternative to safely remove data; it comes by default on Debian/Ubuntu if it doesn’t type:

sudo apt install coreutils

Shred is simple to use too. To overwrite  a file, just type:


To overwrite a zip file named ytfzf-master.zip I run:

shred ytfzf-master.zip

After an ls, we can see the file or directory is still there, but it was overwritten. To remove it after writing, add the –u parameter, as shown below.

shred -u ytfzf-master.zip

Overwriting a Hard Drive With the Scrub Command

The scrub is another tool to overwrite data on hard disks. Scrub writes patterns on files or devices, making data retrieval more difficult. Scrub works in 3 modes detailed on the man page; the default mode is the most effective one.

To install Scrub, run:

sudo apt install scrub

You can wipe a disk with scrub by running the following command, where X must be replaced with your device.

scrub /dev/sdX

To create a directory and fill it with files until the system is full run:

scrub -X


As you can see, wiping hard drives and filesystems is an easy task any Linux user can achieve independently of the knowledge level by just implementing some of the commands previously explained. Linux offers a variety of methods to do the same task, making it easier for users to learn the best for them. Deleting files properly is a basic security measure in shared environments. It is also a good preemptive measure for certain professions like journalists protecting sources, etc. As you can see, using any of the previously described commands is not harder than executing the rm command.

Thank you for reading this tutorial explaining how to completely wipe a hard drive in Ubuntu. Keep following us for additional Linux professional content.

About the author

David Adams

David Adams is a System Admin and writer that is focused on open source technologies, security software, and computer systems.