LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Is it possible to remove all files & folders in a directory without using their names (https://www.linuxquestions.org/questions/linux-newbie-8/is-it-possible-to-remove-all-files-and-folders-in-a-directory-without-using-their-names-926735/)

LAPIII 01-31-2012 10:40 AM

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.

pljvaldez 01-31-2012 10:41 AM

Yup. Use the "*" character and the -r switch for the rm command. man rm

Cedrik 01-31-2012 11:17 AM

Usually /mnt directory is a location to mount things, be sure you double check what you delete here, at it can't be undone

catkin 01-31-2012 10:05 PM

Code:

find /mnt -type f -exec rm '{}' \;

deep27ak 02-01-2012 01:05 AM

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

Code:

#rm -rf /mnt/*

bsat 02-01-2012 05:44 AM

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.

chrism01 02-01-2012 06:29 PM

IOW, given -r = recursive & -f = force, be VERY careful with that ;)

elvinhaak 02-02-2012 03:59 PM

Did this once... deleted entire external HDD which was mounted very, very fast...

suicidaleggroll 02-02-2012 04:18 PM

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.


All times are GMT -5. The time now is 08:46 AM.