LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
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!

Notices


Reply
  Search this Thread
Old 01-31-2012, 11:40 AM   #1
Advice Pro
Member
 
Registered: Mar 2009
Location: Virginia, US
Distribution: Ubuntu 10.10 & Debian 6.0.3,
Posts: 343

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, 11:41 AM   #2
pljvaldez
LQ Guru
 
Registered: Dec 2005
Location: Somewhere on the String
Distribution: Debian Wheezy (x86)
Posts: 6,094

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

Rep: Reputation: 242Reputation: 242Reputation: 242
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, 11:05 PM   #4
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,576
Blog Entries: 31

Rep: Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195
Code:
find /mnt -type f -exec rm '{}' \;
 
Old 02-01-2012, 02:05 AM   #5
deep27ak
Senior Member
 
Registered: Aug 2011
Location: Bangalore, India
Distribution: rhel 5x,6.0,6.2, centOS 5x,6.0,6.2
Posts: 1,194
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

Code:
#rm -rf /mnt/*
 
Old 02-01-2012, 06:44 AM   #6
bsat
Member
 
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, 07:29 PM   #7
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.8, Centos 5.10
Posts: 17,240

Rep: Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324
IOW, given -r = recursive & -f = force, be VERY careful with that
 
Old 02-02-2012, 04:59 PM   #8
elvinhaak
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, 05:18 PM   #9
suicidaleggroll
LQ Guru
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,258

Rep: Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947
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.
 
  


Reply


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 01:35 PM
[SOLVED] List files/directory names without directory contents? littlebigman Linux - Software 2 05-03-2011 05:42 AM
Need to rename files and folders with invalid characters in the names laureynsr Linux - Newbie 5 04-01-2009 04:13 PM
Shell script/cmd to remove old folders in a directory? exxoid Linux - Newbie 1 03-29-2009 02:38 PM
remove ~ from all files and folders BoraX Linux - General 1 10-25-2006 08:58 PM


All times are GMT -5. The time now is 04:42 PM.

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