Linux 101: How to delete files and folders from the CLI

3 years ago 326

In different introduction of his Linux 101 series, Jack Wallen shows you however to delete files and folders from Linux utilizing the Command Line Interface (CLI).

linuxhero3.jpg

Image: Jack Wallen

When you're utilizing a GUI, deleting a record and/or a folder is arsenic elemental arsenic right-clicking and selecting delete. But erstwhile you're logged into a GUI-less server, you won't person that option. What bash you do? 

As you astir apt expected, there's a bid for that. In fact, there's a azygous bid you tin usage for some instances. How you usage that bid varies, depending connected what you're deleting. 

SEE: 5 Linux server distributions you should beryllium using (TechRepublic Premium)

Let maine explain. 

The bid successful question is rm, which stands for remove. The bid is truly elemental to use. For example, you person a record named TEST and you privation to delete it. For that, you'd contented the bid rm TEST. Easy right? 

You tin adjacent usage the bid to delete aggregate files, specified arsenic rm TEST TEST1 TEST2 TEST3

Or you tin region each files that statesman with TEST with rm TEST*

You mightiness person files with spaces successful their names, astatine which constituent you'd request to wrapper the sanction successful azygous quotes, specified arsenic rm 'MY TEST FILE'

But what if that record is really a directory? If you person a directory, named PROJECT, that contains files you don't request anymore, you can't conscionable delete it with the rm PROJECT command, arsenic you'll beryllium informed that PROJECT is directory. 

SEE: Rust: What developers request to cognize astir this programming connection (free PDF) (TechRepublic)

To delete that directory, and its contents, you'd request to bash a recursive/force delete, by adding the -rf options to the command, arsenic successful rm -rf PROJECT

One happening to support successful caput is that the -rf enactment doesn't attraction what it's deleting, truthful usage it with caution. A amended enactment mightiness beryllium to spell the interactive way with rm -ri PROJECT, which volition person you verify each record deletion earlier the bid takes action. And that's each determination is to deleting files and folders from the Linux bid line.

Subscribe to TechRepublic's How To Make Tech Work connected YouTube for each the latest tech proposal for concern pros from Jack Wallen.

Open Source Weekly Newsletter

You don't privation to miss our tips, tutorials, and commentary connected the Linux OS and unfastened root applications. Delivered Tuesdays

Sign up today

Also spot

Read Entire Article