Two Ways To Remove A Directory In Linux - Plus A Bonus Method For Extra Security

Trending 1 hour ago
Best all-around Linux distributions
Jack Wallen / Elyse Betters Picaro / ZDNET

Follow ZDNET: Add america arsenic a preferred source connected Google.


Linux makes interacting pinch your PC and your apps rather straightforward. Anything you tin do connected proprietary operating systems for illustration Windows and MacOS, you tin do pinch nan open-source OS, from nan elemental to nan complicated.  

Often, however, nan simplest tasks tin beryllium a spot confusing, particularly erstwhile you're caller to something. For instance, really do you delete a directory (aka "folder") connected Linux?

Also: The first 8 Linux commands each caller personification should learn

Sounds simple, right? It is! Just for illustration connected MacOS aliases Windows, deleting a directory connected Linux tin beryllium handled by anyone, sloppy of accomplishment level.

I'll show you 2 easy ways to do this, and I'll besides see a prize method that provides a much unafraid measurement to delete a directory.

Method 1: From nan record manager

What you'll need: The only things you'll request for this are a desktop Linux distribution and a directory to delete. I'll show this connected Pop!_OS pinch nan COSMIC desktop, but nan process will beryllium similar, sloppy of Linux distro aliases desktop environment.

I urge creating a trial directory to debar accidentally removing nan incorrect one. To create a caller directory wrong nan record manager, right-click connected immoderate blank spot successful a directory and click New Folder. If you're utilizing KDE Plasma, you'd right-click a blank spot successful nan record head and past click Create New > Folder.

Let's delete nan trial directory you conscionable created. Open your record head and find that directory.

Show more

Right-click nan directory to beryllium deleted and past click Move To Trash. If you don't spot an introduction for Move To Trash, you should spot a Delete entry. 

Show more

The files right-click menu.

Deleting a record from wrong nan Pop!_OS COSMIC record manager.

Screenshot by Jack Wallen/ZDNET

This process useful for some quiet directories and directories that location files/folders. 

Also: My apical 5 password managers for Linux - and my favourite useful connected Windows and MacOS too

You tin past quiet your trash truthful nan record is permanently deleted.

Method 2: From nan bid line

Deleting a directory from nan command line is simply a spot trickier, but not overly difficult. This is done pinch nan rm command.

Open your terminal app

The first measurement is to unfastened your terminal app.

Change into nan correct directory

Next, alteration into nan location that houses nan directory to beryllium deleted. For instance, opportunity nan directory to beryllium deleted is located successful /home/jack/Documents. To alteration into that directory, rumor nan command:

cd ~/Documents

The ~/ is shorthand for your location directory.

Note: You don't have to alteration into nan location lodging nan directory to beryllium removed. If you don't, you'll conscionable request to usage nan afloat way to nan directory to beryllium deleted.

Delete nan directory

Let's opportunity nan directory to beryllium deleted is named TESTING. To delete that directory, sloppy of whether it's quiet aliases contains files/folders, you would delete it pinch nan command:

rm -rf TESTING

If you were to usage only nan bid rm TESTING, it would neglect because you're deleting a directory. The -rf options are:

  • r - recursive - deletes each files/folders wrong nan directory and past deletes nan directory itself.
  • f - forces nan deletion.

You don't person to usage nan f option. For immoderate reason, I conscionable automatically usage it.

You could besides usage nan interactive mode, which would be:

rm -ri TESTING

When deleting successful interactive mode, you will beryllium prompted to OK each step.

Bonus method 

For some, utilizing 1 of nan supra methods isn't enough, particularly if a directory contains files pinch delicate accusation that request to beryllium deleted.

Also: 5 obscure Linux distros you've astir apt ne'er heard of - but should decidedly try

If that's nan case, you'll want to usage nan shred bid to overwrite nan soul files/folders pinch 1s and 0s and past delete nan directory pinch 1 of nan methods above.

The shred bid useful for illustration this:

shred -u -z -n 3 FILE

Where FILE is nan sanction of nan record to beryllium deleted.

The supra options are arsenic follows:

  • -u - Deallocate and region nan record aft overwriting.
  • -z - Add a last overwrite pinch zeros to obfuscate nan shredding.
  • -n X - (where X is simply a number supra 3) indicates really galore iterations are utilized for nan overwriting. The default is 3.

After you've shredded each of nan containing files, delete nan directory pinch your record head aliases nan rm command.

More