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

In one other entry of his Linux 101 collection, Jack Wallen reveals you delete recordsdata and folders from Linux utilizing the Command Line Interface (CLI).


Picture: Jack Wallen

Once you’re utilizing a GUI, deleting a file and/or a folder is so simple as right-clicking and deciding on delete. However whenever you’re logged right into a GUI-less server, you will not have that possibility. What do you do? 

As you most likely anticipated, there is a command for that. In actual fact, there is a single command you should use for each cases. How you employ that command varies, relying on what you are deleting. 

SEE: 5 Linux server distributions you ought to be utilizing (TechRepublic Premium)

Let me clarify. 

The command in query is rm, which stands for take away. The command is basically easy to make use of. For instance, you could have a file named TEST and also you need to delete it. For that, you’d problem the command rm TEST. Straightforward proper? 

You’ll be able to even use the command to delete a number of recordsdata, reminiscent of rm TEST TEST1 TEST2 TEST3

Or you’ll be able to take away all recordsdata that start with TEST with rm TEST*

You may need recordsdata with areas of their names, at which level you’d must wrap the title in single quotes, reminiscent of rm ‘MY TEST FILE’

However what if that file is definitely a listing? In case you have a listing, named PROJECT, that accommodates recordsdata you do not want anymore, you’ll be able to’t simply delete it with the rm PROJECT command, as you will be told that PROJECT is listing. 

SEE: Rust: What builders must find out about this programming language (free PDF) (TechRepublic)

To delete that listing, and its contents, you’d must do a recursive/pressure delete, by including the -rf choices to the command, as in rm -rf PROJECT

One factor to remember is that the -rf possibility does not care what it is deleting, so use it with warning. A greater possibility is perhaps to go the interactive route with rm -ri PROJECT, which can have you confirm each file deletion earlier than the command takes motion. And that is all there’s to deleting recordsdata and folders from the Linux command line.

Subscribe to TechRepublic’s How To Make Tech Work on YouTube for all the most recent tech recommendation for enterprise professionals from Jack Wallen.

Additionally see

Recent Articles


Related Stories

Leave A Reply

Please enter your comment!
Please enter your name here

Stay on op - Ge the daily news in your inbox