Open In App

Ways to Permanently and Securely Delete ‘Files and Directories’ in Linux

Last Updated : 26 Apr, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

Linux is an open-source operating system that is loved by tech geeks. It is a versatile operating system that can be used on thousands of different hardware configurations. The most interesting feature of Linux is its command line interface. This feature allows you to perform multiple operations within the operating system with just a few commands. One of the most useful commands in the Linux command line is the rm command. You can use this command to delete files and directories within the operating system. But, if you use rm to remove a file, it might be possible to recover some of its contents, given sufficient expertise and time.

So, there are 6 Different ways to Permanently and Securely Delete ‘Files and Directories in Linux. 

  • Method 1: Shred command 
  • Method 2: Wipe Command
  • Method 3: Using Secure-delete Package ToolKit
  • Method 4: SFill (secure free disk and inode space wiper)
  • Method 5: Sswap – Secure Swap Wiper
  • Method 6: sdmem – Secure Memory Wiper

Let’s Explore one by one:

Method 1: Shred command 

In Linux, the Shred command allows one to remove a file by deleting all its data which might be present within the files’ directories (or even parts thereof). This article provides an overview of how to perform these operations in GNU tarball archive format and highlights possible ways of performing them with certain utilities such as shlib-util library or libsdl2d. After reading I’ll cover some important tips that you can utilize when searching through those sources! You will find information about running several commands from /dev/urandom device, so it’s advised whenever starting new scripts use ‘sh’. 

Arguments:

  • -z: Overwrite with 0
  • -v: Displays The progress step by step
  • -u: Removes file after overwriting
  • -n: Specifies the number of times the operation should be performed
shred -zvu -n  5 Akash.c
Shred command

Shred command 

Method 2: Wipe Command

In Linux, the Wipe command is used to set the default filesystem of files (or any other partition) that are mounted and protected by a volume on which they reside. You can use this option if you want to keep your data safe from corruption without backing it up with disk space before trying something new or modifying its contents when needed.

Installation of wipe:

sudo apt-get install wipe

Syntax: 

wipe -rfi <folder>
  • -r: Recursion
  • -f: Force Delete
  • -i: Displays Status (Info)

Command:

mkdir temp_del // Create a temp dir to demonstrate
ls
cd temp_del
mkdir ak // create folder ak under temp dir
touch c.c // create c.c file under temp dir
ls
cd ../.
wipe -rfi temp_del // wipe and delete recursively
ls
Wipe Command

Wipe Command

Method 3: Using Secure-delete Package Toolkit

In Linux, the Secure-delete command is used to delete a file from your filesystem. When you run it in a terminal like this: “ls -l | tr ‘\r ‘ foo1” that will print all the files we are deleting so far and give us some options for how many additional folders there are after each one (included). We can then get back into the root of any existing directory using bash with sudo chown. You do not have security concerns if they append /usr/local/bin as the first user but having specific permissions when creating users etc does help prevent attacks where someone gains access at system level too easily.

Installation:

sudo apt-get install secure-delete

Syntax: 

srm -vzr <path>
  • -v: Verbose Logging
  • -z: writes 0
  • -r: Recursion

Command:

srm -vz temp // Not using R doesnt delete the directory

ls

srm -vzr temp // Using R removes the directory as well

ls

removing directory using secure delete

removing directory using secure delete

Memory Management in Linux

Managing computer memory is an important task for any operating system. Controlling the amount of memory in a computer is crucial to its functionality. Linux provides several internal commands for managing memory, but the user can add additional functionality through programming. Several options let users control how long programs run, how much physical memory each program uses, and how much space each file occupies on the hard drive. Linux memory management options include sfill , sswap and sdmem .
 

Method 4: SFill (secure free disk and inode space wiper)

sfill and sswax enable the compaction of unused or partially used physical memory blocks. Programmers can use these commands to free up excess RAM space on the system. /proc/cpuinfo Uses the CPUID kernel information for a given core instead of system load since this is more convenient if you have to disable most caches when doing benchmarking in-process using hardware profilers. -m CONFIG_SUSPICIOUS This option controls whether SUSE provides statistics about how busy an affected process was compared with what it should be working hard at any particular time: 0 indicates not bothered; 1 means annoyed; 2 means constantly buzzing around (this makes sense).

ls
sudo sfill -fiIlvz temp
secure free disk and inode space wiper

secure free disk and inode space wiper

Method 5: Sswap (Secure Swap Wiper)

The sswap command performs a similar function, but for swap space on the hard drive. Linux supports many types of memory, including DRAM, SRAM, and flash. These commands can be used to compact any type of physical memory. swapon /all A symlink as specified in another system’s configuration file or from within an image that has been created with some special options (see Formatting Image Contents). When invoked without arguments, it unmounts all files using write-only storage: do not change this if you don’t want your images or other documents or data copied over these filesystem changes. If no parameters are given, nothing happens after swapping is complete, so return status codes will become 0.

ls
sudo sswap temp
ls
Secure Swap Wiper

Secure Swap Wiper

Method 6: sdmem (Secure Memory Wiper)

The sdmem command adds a memory compaction feature to the Linux mem command. It enables Linux to clean up old or unused chunks of physical memory. This makes it ideal for managing RAM space used by the operating system itself. The Linux commands work on any type of physical memory, including DDR3, DDR2, DDR, and SRAM. This makes them a powerful tool for system administrators and programmers alike.

ls
sdmem
sdmem temp
sdmem -f temp
sdmem -f
Secure Memory Wiper

sdmem (Secure Memory Wiper)

Frequently Asked Questions

1) 3 Ways to Permanently and Securely Delete ‘Files and Directories’ in Linux?

We have three common ways to delete `Files and Directories` permanently and securely in Linux.

  •  Shred:
shred -zvu -n 4 [file_name]
  1. -z – adds a final overwrite with zeros to hide shredding
  2. -v – operation progress is displayed
  3. -u – removes and truncates file after overwriting
  4. -n – number of times we want to overwrite file content (the default is 3) we have chosen 4 times in this example.
  5. file_name = can enter any file you want
  •  Wipe:

Install wipe tool 

#for Debian-baised linux operating system like ubuntu
sudo apt-get install wipe

#for Red Hat baised linux operating system like RHEL
sudo yum install wipe
         or
sudo dnf install wipe

Here is the syntax 

wipe -rfi [Directory_name]
  1. -r – recurse into subdirectories
  2. -f – forced deletion and no confirmation query
  3. -i – to see progress of deletion process

To see manual of wipe

man wipe 
  •  Secure-deletion Toolkit: 

Install secure-delete

#for Debian-baised linux operating system like ubuntu
sudo apt-get install secure-delete

#for Red Hat baised linux operating system like RHEL
sudo yum install secure-delete
         or
sudo dnf install secure-delete

Here is the syntax

srm -vz [directory_name]
  1. -v – verbose mode on
  2. -z – wipes the last write with zeros instead of random data

To see manual of secure-deletion

man srm

2) Does rm delete permanently?

When we delete a file or directory permanently with help of `rm` command, it is for sure deleted. It is somehow possible to recover recently deleted data in this case, if it is not yet overwritten by other data. Once a deleted file or directory is overwritten by data it is kind of impossible to recover the data. 

3) What is secure file deletion?

When we delete a file from our system, it is deleted for sure and cannot be seen if we search or find it, but the actual file remains on hard disk after deletion also. So, we have to securely delete our file, directory or critical tasks.
A process of deleting sensitive data and critical tasks, that should not be able to be recovered by anyone after deletion.

Conclusion

Linux is an open-source operating system known for its flexibility and interface. One of the most used commands in Linux is `rm` which do delete files but not permanently, it is possible for professionals to recover that data. To permanently delete a file in Linux we have mentioned six ways to do so, shred command, wipe and the Secure-delete package toolkit. We have some tools like sfill, sswap and sdmem for memory management by which users can be sure that their data is permanently deleted or not from the system.



Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads