How7o
  • Home
  • Marketing
    MarketingShow More
  • OS
    OSShow More
    How to force quit frozen apps in Ubuntu
    Force Close an App in Ubuntu (xkill, System Monitor, kill -9)
    4 Min Read
  • Features
    FeaturesShow More
  • Guide
    GuideShow More
  • Contact
  • Blog
Reading: How to Remove Files and Folders in Linux Using Command Line (rm, rmdir, unlink)
Share
Subscribe Now
How7oHow7o
Font ResizerAa
  • Marketing
  • OS
  • Features
  • Guide
  • Complaint
  • Advertise
Search
  • Categories
    • Marketing
    • OS
    • Features
    • Guide
    • Lifestyle
    • Wellness
    • Healthy
    • Nutrition
  • More Foxiz
    • Blog Index
    • Complaint
    • Sitemap
    • Advertise
Follow US
Copyright © 2014-2023 Ruby Theme Ltd. All Rights Reserved.
How7o > Blog > Server Management > How to Remove Files and Folders in Linux Using Command Line (rm, rmdir, unlink)
Server Management

How to Remove Files and Folders in Linux Using Command Line (rm, rmdir, unlink)

how7o
By how7o
Last updated: January 22, 2026
5 Min Read
Remove Files & Folders in Linux
SHARE

I still remember my early Linux days—every simple task felt risky, especially deleting things. On Windows you have the Recycle Bin. On Linux, when you delete from the terminal… it’s usually gone. That “no undo button” feeling is exactly why people say Linux is hard.

Contents
  • Important warning before you delete anything
  • How to remove files in Linux
    • 1) Remove a single file using unlink
    • 2) Remove a single file using rm
    • 3) Remove multiple files at once
    • 4) Remove files by extension (wildcard *)
    • 5) Force delete a file (rm -f)
  • How to remove folders (directories) in Linux
    • 1) Remove an empty directory (rmdir)
    • 2) Remove an empty directory using rm -d
    • 3) Remove a directory with files inside (rm -r)
    • 4) Remove a directory and contents without prompts (rm -rf)
    • 5) Remove multiple directories at once
  • My “safe delete” habits (highly recommended)
  • Conclusion

But honestly, Linux isn’t hard—most of us just don’t use it daily. Once you understand a few commands, it becomes predictable. In this guide, I’ll show you how to remove files and folders in Linux using command line the safe way. We’ll cover rm, unlink, and rmdir, with practical examples you can copy and use.

Important warning before you delete anything

When you delete files from the Linux terminal, there’s usually no trash/recycle bin. If you remove the wrong file, recovery is painful (and sometimes impossible). So I follow these two habits:

  • Always run ls (or ls -la) before deleting, to confirm filenames.
  • If I’m deleting many files, I use interactive mode first (rm -i) to avoid mistakes.

How to remove files in Linux

To delete a file, Linux gives you two common commands:

  • unlink (removes a single file)
  • rm (removes one or many files, and can remove folders too)

1) Remove a single file using unlink

unlink is simple and strict—it deletes only one file at a time:

unlink filename

If you need to remove multiple files, use rm instead.

2) Remove a single file using rm

rm filename

If the file is write-protected, Linux may ask for confirmation:

rm: remove write-protected regular file 'filename'?

Type y and press Enter to confirm.

3) Remove multiple files at once

List file names separated by spaces:

rm file1 file2 file3

4) Remove files by extension (wildcard *)

If you want to remove all files of the same type (example: all .mp4 files):

rm *.mp4

Safety tip: Before running a wildcard delete, preview what will match using: ls *.mp4

5) Force delete a file (rm -f)

If you want to delete without confirmation prompts, use -f (force):

rm -f filename

Be careful: -f is powerful and can hide mistakes, so I only use it when I’m 100% sure.


How to remove folders (directories) in Linux

For directories, you usually use:

  • rmdir (removes only empty folders)
  • rm (can remove empty or non-empty folders, depending on options)

1) Remove an empty directory (rmdir)

rmdir dirname

If the directory has files inside, rmdir will fail.

2) Remove an empty directory using rm -d

This also works for empty directories:

rm -d dirname

3) Remove a directory with files inside (rm -r)

To delete a folder and everything inside it, use -r (recursive):

rm -r dirname

If there are write-protected files, Linux may ask for confirmation for each file. That can be annoying when deleting big folders.

4) Remove a directory and contents without prompts (rm -rf)

If you want to remove a non-empty folder without being asked anything:

rm -rf dirname

Warning: rm -rf is one of the most dangerous commands on Linux. Double-check the path. A tiny typo can delete the wrong directory.

5) Remove multiple directories at once

You can remove multiple directories by listing them:

rm -r dir1 dir2 dir3

Or force + recursive (no prompts):

rm -rf dir1 dir2 dir3

My “safe delete” habits (highly recommended)

  • Preview wildcards: ls *.log before rm *.log
  • Use interactive delete when unsure: rm -i filename
  • For folders, start with: rm -ri dirname (recursive + interactive)
  • Always verify your working directory: pwd

Conclusion

That’s it. Now you know how to remove files and folders in Linux using command line—using rm, unlink, and rmdir. The commands are simple, but they’re powerful, so always pause for two seconds before you hit Enter. Once you build the habit of checking paths and previewing wildcards, deleting files in Linux becomes easy and safe.

TAGGED:centoscommand-lineLinuxrmrmdirsysadminterminalUbuntuunlink

Sign Up For Daily Newsletter

Be keep up! Get the latest breaking news delivered straight to your inbox.
By signing up, you agree to our Terms of Use and acknowledge the data practices in our Privacy Policy. You may unsubscribe at any time.
Share This Article
Facebook Copy Link Print
Previous Article Configure Nginx for WordPress in aaPanel (fix 404 permalinks) Configure Nginx for WordPress in aaPanel (Fix Permalink 404 Errors)
Next Article Include Composer packages in plain PHP projects How to Include Composer Packages in Plain PHP Projects (Autoload + Example)
Leave a Comment

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

FacebookLike
XFollow
PinterestPin
InstagramFollow

Subscribe Now

Subscribe to our newsletter to get our newest articles instantly!
Most Popular
CyberPanel too many redirects Laravel error fixed by restarting LiteSpeed
Fix CyberPanel Too Many Redirects (ERR_TOO_MANY_REDIRECTS) for Laravel Subdomain
January 23, 2026
How I Fixed Composer Dependency Errors
How I Fixed Composer Dependency Errors Using the –ignore-platform-reqs Flag (Step-by-Step Guide)
January 12, 2026
Transfer Discourse to a new server
How to Transfer Discourse to a New Server on AlmaLinux (Backup + Restore, Step-by-Step)
January 12, 2026
Installed Discourse on AlmaLinux
How I Installed Discourse on AlmaLinux (Docker Method, Step-by-Step)
January 12, 2026
Installing Docker on AlmaLinux guide
Install Docker on AlmaLinux: Step-by-Step (Docker CE + Compose)
January 12, 2026

You Might Also Like

Change welcome message on Ubuntu VPS server (MOTD + SSH banner)
Server Management

Change Welcome Message on Ubuntu VPS (MOTD + SSH Banner)

6 Min Read
Check if Laravel scheduler is running (cron + php artisan schedule:run)
Web Development

How to Check if Laravel Scheduler Is Running (Cron + Logs)

6 Min Read
Automatic logout timeout for command line in Ubuntu (TMOUT 300s)
Server Management

Automatic Logout Timeout for Command Line in Ubuntu (TMOUT 300s)

5 Min Read
How to temporarily disable Imunify360 service for testing (cPanel/WHM)
Server Management

How to Temporarily Disable Imunify360 Service (Safe Testing + Fix 503)

5 Min Read

Always Stay Up to Date

Subscribe to our newsletter to get our newest articles instantly!
How7o

We provide tips, tricks, and advice for improving websites and doing better search.

Latest News

  • SEO Audit Tool
  • Client ReferralsNew
  • Execution of SEO
  • Reporting Tool

Resouce

  • Google Search Console
  • Google Keyword Planner
  • Google OptimiseHot
  • SEO Spider

Get the Top 10 in Search!

Looking for a trustworthy service to optimize the company website?
Request a Quote
Welcome Back!

Sign in to your account

Username or Email Address
Password

Lost your password?