Undetectable Humanizer: Lifetime Subscription
Transform AI-Generated Text into Human-Like, High-Ranking Content & Bypass Even the Most Sophisticated AI Detectors
Get 95% Deal

Get to know Linux: Removing files

Jack Wallen
May 20, 2009
Updated • Dec 28, 2012
Linux
|
3

As you all know, with Linux there are numerous ways to deal with each and every task. Some of these ways are obvious, some are subtle, and some are as brute-force as an NFL offensive line. Each of these methods will do the same thing but, in some cases, the results are a bit different.

Such is the case with removing files. There are two fundamental ways to remove a file:

With the help of a GUI such as Thunar, Dolphin, or Nautilus

With the help of a command such as rm or shred.

In this article we will primarily examine the latter and touch on the former.

The former - GUI

As you would expect, in all three of the graphical file managers you can easily remove a file simply by right clicking the file and selecting Delete. There are, however, some subtle differences. You will notice, in both Dolphin and Nautilus you can choose between Deleting a file and moving a file to the Trash. This behavior mimics that of Windows Explorer. Once you move a file to the Trash it will remain there until you empty your trash. Should you select to actually Delete the file, however, that file is deleted right away.

This behavior is not available in Thunar. With Thunar you can keep it or delete it.

rm that file

The basic remove command is rm. It is used like this:

rm OPTIONS

Believe it or not there are options to go along with the rm command. There are two options that are used most often:

f - This option will force the delete. In other words you will not have to answer "y" to every file you want to delete. This is very handy when you are deleted a directory.

r - This option will recursively delete all files within a directory as well as the directory itself.

As you can surmise, the r and f options are most often used together. So to delete the ~/TEST directory and all of its files you would issue the command:

rm -rf ~/TEST

If you only wanted to delete the file test.txt within the ~/TEST directory you would issue the command:

rm ~/TEST/test.txt

What if you wanted to delete all jpg files within the ~/TEST directory? Simple:

rm -f ~/TEST/*.jpg

The * character is a wild card which means, in this case, anything that ends with .jpg. Notice the ".". If you leave that out you can delete any file ending in jpg - not just any file with the extension .jpg.

shredd'ing a file

The shred command is a whole different beast. Shred is for the paranoid. Shred completely obliviates a file by overwriting its contents. Instead of deleting a file shred will simply overwrite a file and the end results will be an unreadable binary file that can then be safely removed.

And no matter how paranoid you are, shred will help you out. You can declare how many overwrite iterations shred will perform. You can even add a final overwrite of nothing but zeros to hide the fact that you ever shredded a file. And finally, you can also add a switch to inform shred to automatically remove the file after the iterations.

Shred is used like so:

shred OPTIONS filename

The most popular options are:

v - Show progress.

z - Add final overwrite of zeros.

u - Remove file after iterations

n - Overwrites n times

So to shred a file by iterating 10 times, followed by a final iteration of zeros, and then deleting the file upon completion you would issue the command:

shred -v -n 10 -z  FILENAME -u

Where FILENAME is the actual file name.

After that command your removed file has vanished into thin air.

Final thoughts

Many different routes to the same destination. Of this, Linux is the master. In the case of removing files, you can send it to the trash for possible later easy retrieval, remove it with the possibility of a much more difficult retrieval, or shred it with no hopes of retrieval. Your call.

Advertisement

Previous Post: «
Next Post: «

Comments

  1. jack said on May 20, 2009 at 1:47 pm
    Reply

    looks like that just made it into the 1.0.0 release a couple of months ago. believe it or not all of my debian installs have 0.9.0 on them which does not have this feature.

    thanks for pointing this out!

  2. G David Lewis said on May 20, 2009 at 1:33 pm
    Reply

    One of the best things about Linux is the ability to quickly and easily throw frequently and commonly used commands along with any options into a quick script. For instance, with the shred command above, one could use this simple little script…

    #!/bin/bash

    shred -v -n 10 -z $@ -u

    exit

    …where the $@ would represent any file(s) passed to the script on the commandline. Throw this into a text file, name it something like “obliterate’, make it executable and place it somewhere in your path or even on your desktop. Then instead of typing all that, you can simply type “obliterate filename(s)”, or drag and drop the file(s) onto the icon for the script and poof – they will be gone!

    Such is the power of Linux, it’s a beautiful thing!

  3. Tom said on May 20, 2009 at 12:57 pm
    Reply

    Hi,

    if I understand you correctly, you are saying that Thunar does not have a Trash, right?

    But this is not the case for Xubuntu. Here the Thrash works like under Windows.

    Tom

Leave a Reply

Check the box to consent to your data being stored in line with the guidelines set out in our privacy policy

We love comments and welcome thoughtful and civilized discussion. Rudeness and personal attacks will not be tolerated. Please stay on-topic.
Please note that your comment may not appear immediately after you post it.