Visit Jeremy's Blog.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 01-31-2012, 10:40 AM   #1
Registered: Mar 2009
Location: Virginia, US
Distribution: Ubuntu 10.10 & Debian 6.0.3,
Posts: 345

Rep: Reputation: 7
Is it possible to remove all files & folders in a directory without using their names

For example, my mnt directory consists of two folders, with 16 files in each, and 48 files.
Old 01-31-2012, 10:41 AM   #2
LQ Guru
Registered: Dec 2005
Location: Somewhere on the String
Distribution: Debian Wheezy (x86)
Posts: 6,094

Rep: Reputation: 272Reputation: 272Reputation: 272
Yup. Use the "*" character and the -r switch for the rm command. man rm
Old 01-31-2012, 11:17 AM   #3
Senior Member
Registered: Jul 2004
Distribution: Slackware
Posts: 2,140

Rep: Reputation: 243Reputation: 243Reputation: 243
Usually /mnt directory is a location to mount things, be sure you double check what you delete here, at it can't be undone
Old 01-31-2012, 10:05 PM   #4
LQ 5k Club
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,577
Blog Entries: 31

Rep: Reputation: 1196Reputation: 1196Reputation: 1196Reputation: 1196Reputation: 1196Reputation: 1196Reputation: 1196Reputation: 1196Reputation: 1196
find /mnt -type f -exec rm '{}' \;
Old 02-01-2012, 01:05 AM   #5
Senior Member
Registered: Aug 2011
Location: Bangalore, India
Distribution: RHEL 7.x, SLES 11 SP2/3/4
Posts: 1,195
Blog Entries: 4

Rep: Reputation: 221Reputation: 221Reputation: 221
I am not very sure if I get it correctly but if you want to delete everything inside /mnt

#rm -rf /mnt/*
Old 02-01-2012, 05:44 AM   #6
Registered: Feb 2009
Posts: 347

Rep: Reputation: 72
rm -rf would be the right thing for usual directories but it is surely not recommended for /mnt. You would generally want to unomount things that are present under /mnt, so please be careful before you do that.
Old 02-01-2012, 06:29 PM   #7
LQ Guru
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.10, Centos 7.5
Posts: 17,670

Rep: Reputation: 2487Reputation: 2487Reputation: 2487Reputation: 2487Reputation: 2487Reputation: 2487Reputation: 2487Reputation: 2487Reputation: 2487Reputation: 2487Reputation: 2487
IOW, given -r = recursive & -f = force, be VERY careful with that
Old 02-02-2012, 03:59 PM   #8
LQ Newbie
Registered: Jan 2012
Posts: 14

Rep: Reputation: Disabled
Did this once... deleted entire external HDD which was mounted very, very fast...
Old 02-02-2012, 04:18 PM   #9
LQ Guru
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,573

Rep: Reputation: 2134Reputation: 2134Reputation: 2134Reputation: 2134Reputation: 2134Reputation: 2134Reputation: 2134Reputation: 2134Reputation: 2134Reputation: 2134Reputation: 2134
When I was first getting started with Linux I once ran "rm -fr *" by accident when I was root in /

After re-installing the OS, I never made that mistake again.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Remove whitespace in file and directory names using bash TheFutonEng Programming 14 02-26-2012 12:35 PM
[SOLVED] List files/directory names without directory contents? littlebigman Linux - Software 2 05-03-2011 04:42 AM
Need to rename files and folders with invalid characters in the names laureynsr Linux - Newbie 5 04-01-2009 03:13 PM
Shell script/cmd to remove old folders in a directory? exxoid Linux - Newbie 1 03-29-2009 01:38 PM
remove ~ from all files and folders BoraX Linux - General 1 10-25-2006 07:58 PM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 02:55 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration