LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
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-06-2009, 03:55 PM   #1
ceantuco
Member
 
Registered: Mar 2008
Location: New Jersey
Distribution: CentOS, Debian, Kali
Posts: 577

Rep: Reputation: 37
Cool command to delete folders on /tmp


hi guys,

how can I use the rm command to delete folders on /tmp .

I tried # rm -fr /tmp/*.* but that only erases files and not folders.
Can you guys help me?
I checked the MAN info on rm but couldn't find something that will do it. I also googled it but I had no luck.
thanks
 
Old 01-06-2009, 04:06 PM   #2
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976
I would tell it erases only files with a dot in their name. To remove only the directories inside /tmp, first find them:
Code:
find /tmp -mindepth 1 -type d -print0 | xargs -0 rm -rf
the option mindepth 1 excludes the /tmp directory itself. First try the find command without the option -print0 and without piping the output to xargs. If the resulting list of directories is exactly the list you want to remove, then you can safely apply the whole command.
 
Old 01-06-2009, 04:10 PM   #3
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976
Another simple solution is
Code:
rm -rf /tmp/*/
Adding the trailing slash forces the shell to expand to the directories names only.
 
Old 01-06-2009, 04:20 PM   #4
ceantuco
Member
 
Registered: Mar 2008
Location: New Jersey
Distribution: CentOS, Debian, Kali
Posts: 577

Original Poster
Rep: Reputation: 37
the second option worked just fine! THANKX!
 
Old 01-07-2009, 10:44 AM   #5
saagar
Member
 
Registered: Jul 2008
Location: Chennai, India
Distribution: RHEL5, Ubuntu
Posts: 191

Rep: Reputation: 37
KISS
 
Old 01-07-2009, 03:17 PM   #6
ceantuco
Member
 
Registered: Mar 2008
Location: New Jersey
Distribution: CentOS, Debian, Kali
Posts: 577

Original Poster
Rep: Reputation: 37
Question ???

Quote:
Originally Posted by saagar View Post
KISS
???
 
Old 01-07-2009, 03:24 PM   #7
SqdnGuns
Member
 
Registered: Aug 2005
Distribution: Slackware64 14.2 w/ CSB & MSB
Posts: 998

Rep: Reputation: 96
Quote:
Originally Posted by saagar View Post
KISS
Keep It Simple Stupid

Not an insult, no need to worry or get your knickers in a bunch.
 
Old 01-08-2009, 09:10 AM   #8
ceantuco
Member
 
Registered: Mar 2008
Location: New Jersey
Distribution: CentOS, Debian, Kali
Posts: 577

Original Poster
Rep: Reputation: 37
LOL that's a good one!!! like ID-10-T!!!!
 
  


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
what is the command to delete files and folders quickly. ravi Linux - General 1 03-13-2007 01:09 PM
Is it OK to delete everything in /tmp? forrest44 Slackware 12 11-15-2005 11:47 PM
How do I delete /tmp partition? akihandyman Mandriva 4 08-08-2004 03:38 PM
Can I delete everything in the /tmp directory? BajaNick Linux - General 5 07-04-2004 02:35 PM
Delete all in /tmp ??? shreev Slackware 5 08-07-2003 05:12 PM


All times are GMT -5. The time now is 10:21 AM.

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