Linux Command srm Usage and 5 Options

The Linux command srm allows you to securely delete files by overwriting them multiple times, ensuring that the files are completely removed. Many Linux users typically use the rm command to delete files. However, files deleted using rm are not truly erased; traces remain on the disk, making them recoverable through data recovery programs. For this reason, in environments where sensitive data is handled or security is crucial, a command that can fully delete files is needed. One such command is srm.

What is the Linux Command srm?

srm stands for “secure remove,” and it is used to delete files in a way that makes them impossible to recover. It overwrites the data on the disk multiple times, leaving no trace behind, making it especially useful for deleting sensitive information or confidential company files.

The default behavior of srm is to overwrite the file 38 times, using the following method: First, all bits of the file are filled with 1s. Then, the file is overwritten five times with random values. Next, it is overwritten 27 times with specific values as defined by Peter Gutmann. Finally, the file is overwritten five more times with random values, the filename is renamed with random characters, and the file is permanently deleted.

srm vs rm

The main difference between rm and srm is in how they delete data. While rm simply deletes the file’s reference, leaving the data intact on the disk (making it recoverable), srm overwrites the data multiple times, making recovery extremely difficult. Another command with similar functionality is wipe.

How to Install srm

Most Linux distributions do not include the srm command by default, so you will need to install it separately. On Ubuntu or Debian-based systems, you can install it with the following command:

sudo apt install secure-delete
ShellScript

Once installed, you can start using the srm command.

Basic Usage of srm

The basic usage of the srm command is quite simple. To delete a file, just type srm followed by the file path.

srm filename
ShellScript

For example, if you want to delete a file named example.txt, you would enter the following command:

srm example.txt
ShellScript

This will fully delete the example.txt file by overwriting it multiple times. Once the deletion process is complete, the command prompt will return without any additional messages.

Figure 1. Linux command srm: basic usage
Figure 1. Linux command srm: basic usage

Main Options for the srm Command

The srm command provides several options that allow you to customize how files are deleted. Below are the key options:

-r (recursive)

This option is used when you want to delete all files within a directory. With the -r option, you can delete a directory along with all its files and subdirectories.

srm -r subdir
ShellScript

-v (verbose)

If you want to see detailed information about the deletion process, use the -v option. This will show you the progress of the deletion in the terminal.

srm -v filename
ShellScript

When using the -v option, you can view the detailed steps of the file deletion as shown in the example below.

Figure 2. Linux command srm: viewing the deletion process with the -v option
Figure 2. Linux command srm: viewing the deletion process with the -v option

-l (less secure)

If you want to use a slightly less secure deletion method, the -l option is available. By default, srm overwrites files 38 times for maximum security, but using the -l option reduces the number of overwrites to 2, speeding up the process.

srm -l filename
ShellScript

With the -l option, files are overwritten only twice—once by filling all bits with 1s and once with random values.

Figure 3. Linux command srm: overwriting only twice with the -l option
Figure 3. Linux command srm: overwriting only twice with the -l option

-f (fast and insecure mode)

The -f option allows for fast deletion in an insecure mode. It does not use /dev/urandom or synchronization mode for overwriting files.

srm -f filename
ShellScript

Although the deletion process remains at 38 overwrites, the -f option skips random value overwriting and synchronization.

Figure 4. Linux command srm: fast deletion with the -f option
Figure 4. Linux command srm: fast deletion with the -f option

-z (zero)

After overwriting the file 38 times, the -z option writes zeros to the remaining free space on the disk. This option is useful when you want to completely fill all the freed space with zeros after deleting files.

srm -z filename
ShellScript

Usage Considerations

There are a few things to be aware of when using the srm command:

  1. Irreversibility: Unlike the wipe command, which prompts for confirmation before deletion, srm deletes files immediately without asking. Once deleted, files cannot be recovered, so double-check before deletion. Always verify the files you are about to delete.
  2. Performance Impact: Since srm overwrites files multiple times, it takes longer to delete files compared to the rm command. For large files or many files, this process can be significantly slower.
  3. Disk Wear: Overwriting files multiple times can shorten the lifespan of SSDs and other flash-based storage devices. Be cautious when using the srm command on such devices.

Useful Applications

The Linux command srm is especially valuable in environments where security is critical. Here are some scenarios where it can be applied:

  • Personal Data Protection: Use srm to securely delete sensitive personal or customer data, preventing any possibility of leakage.
  • Disk Cleanup: When clearing out old files, you can use srm to ensure that no traces of the deleted files remain. It’s particularly useful if you’re selling or transferring a disk to someone else, reducing the risk of data recovery.

Additionally, you can automate the deletion of sensitive files by including the srm command in a regular script. This makes it easier to manage confidential data without the need for manual deletion.

Summary

The Linux command srm is a powerful tool for securely deleting files, ensuring that they are unrecoverable. In environments where security is essential, using srm instead of rm is a smart way to manage sensitive data. However, you should be aware of the potential performance impact and the irreversibility of the deletion process. Moreover, care should be taken when using srm on SSDs and other flash-based storage devices to avoid unnecessary wear.

References

Leave a Comment