How To Delete Files and Directories via the Linux Terminal

Files and directories in a trashcan
(Image credit: Pexels / OpenClipArt)

Deleting directories and files is one of the most basic, but important functions in any operating system. In Linux, if you have a windowed environment running, you can locate and delete files using a file manager application. Perhaps you’re logging in remotely via SSH, your Linux computer doesn’t have a GUI installed or you want to have more control over what you’re deleting. As with anything in Linux, there are many reasons why it might be necessary or preferable to delete directories or files via the command line.

In this how-to, we’ll look at the rm command which removes directories and files. We’ll look at the basics of the command and how it can be used to remove both files and directories and we’ll also look at a few other enhancements to get the most out of this command. If you want to change your file’s location instead, you should check out our article on how to move and rename files in Linux.

Latest Videos FromTom's Hardware
TOPICS
Jo Hinchliffe
Contributing Writer

Jo Hinchliffe is a UK-based freelance writer for Tom's Hardware US. His writing is focused on tutorials for the Linux command line. From PCBs to rowing boats to rockets, Jo tries wherever possible to integrate open source hardware and software into his projects. As such he is a keen Linux user, has authored a book on FreeCAD the open source 3D modeling software, and has published designs and tutorials across a wide range of makes.

With contributions from