How To Remove All Files From the Current Directory Using Terminal on Linux/Ubuntu
Managing files in Ubuntu through the terminal can feel a bit intimidating if you’re not used to it. Sometimes, after a big project cleanup or just trying to clear out clutter, you want to delete everything in a directory without messing around with folder structures or manually selecting files. The commands here are pretty straightforward but powerful — a small typo can delete more than intended, so caution’s key. This guide will walk through how to safely wipe out all files and even folders from your current spot in the terminal. Once done, you’ll have a clean slate, and hopefully, this makes your workflow a lot smoother.
How to Fix the ‘Remove All Files’ in Ubuntu Terminal
Open the Terminal
First things first, get that terminal open. The fastest way is pressing Ctrl + Alt + T. Honestly, on most Ubuntu setups, this shortcut works like a charm. If it doesn’t, you can find the terminal in Applications > Utilities > Terminal. From here, you’ll be entering all your commands.
Pro tip: some setups might require you to press Super + T, but Ctrl + Alt + T is pretty universal for Ubuntu.
Check Your Current Directory — Critical Step
Before doing anything destructive, you gotta verify where you are. Running pwd
(print working directory) will show you the current path. This helps avoid wiping out important system or personal files randomly. Because of course, Ubuntu has to make it harder than necessary sometimes.
pwd
List Files and Folders
Next, see what’s actually in there before you delete anything. Typing ls
will list all visible files and folders in that directory. If hidden files might matter, try ls -a
. It’s good to double-check because, frankly, some hidden configs or dot files might also be critical — or just clutter, whatever.
ls
Remove Only Files — Keep the Folders
If you just want to delete all the files, leaving folders untouched, here’s the simple trick: rm *
. It deletes everything that’s not a directory, which is useful for quick tidying. But beware: this won’t touch hidden files (the ones starting with a dot). On some setups, you might need rm .* *
, but that can get messy—so stick with rm *
for now.
If you find that files aren’t deleting or you get permission errors, try prefixing with sudo
, like sudo rm *
. Just be super careful, because this command deletes without asking.
This is kind of weird, but on some machines, the first run might not delete everything due to permissions, yet a second attempt after elevated permissions will do the job.
Completely Wipe Out Everything (Files + Folders)
Here’s the big one: to delete all contents (files and folders), use rm -rf *
. The -r
makes it recursive, so it clears folders and all their subfolders, while -f
forces deletion without prompting. This is dangerous, especially if you’re in the wrong place, so triple-check with pwd
first.
On some setups, executing rm -rf *
in your home directory or root can erase way more than intended. So, yes, double (or triple) check that you’re in the right directory before slamming this in.
Confirm Your Location Before Running the Delete Command
Good practice — run pwd
again just before hitting rm -rf *
. It’s easy to overlook your current directory, especially if you switch between multiple terminal tabs or windows. Nobody wants to accidentally wipe their root or system folders.
Extra Tips & Common Pitfalls
- Backups are your friend — especially before heavy deletions. If you’re unsure, copy the folder somewhere safe first.
- Use
rm -i
if you wanna be prompted for each delete — better safe than sorry, but it’s slower. - Hidden files matter sometimes, so don’t forget to
ls -a
. You might miss a dot file that’s critical or just cluttered. - Because, of course, some files might be protected or owned by root. Using
sudo
helps, but it increases risks, so only run it if you know what you’re doing.
Wrap-up
Once these steps are done, your directory should be squeaky clean. Just remember: double-check your current location and back up what’s important. These commands are powerful but dangerous if misused — and trust me, it’s surprisingly easy to delete more than expected if you’re not paying attention.
Summary
- Use
pwd
to verify directory - Run
ls
orls -a
to see what’s inside - Type
rm *
for files only, orrm -rf *
to wipe everything - Always double-check the current folder before executing delete commands
- Be cautious with
sudo
— it’s a powerful tool, but easy to abuse
Fingers crossed this helps
If this gets one setup cleaned without chaos, it’s a win. Just takes a bit of attention and respect for what these commands can do. Happy deleting!