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-06-2009, 02:55 PM   #1
ceantuco
Member
 
Registered: Mar 2008
Location: New York
Distribution: Debian
Posts: 809

Rep: Reputation: 88
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, 03:06 PM   #2
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
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, 03:10 PM   #3
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
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, 03:20 PM   #4
ceantuco
Member
 
Registered: Mar 2008
Location: New York
Distribution: Debian
Posts: 809

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

Rep: Reputation: 37
KISS
 
Old 01-07-2009, 02:17 PM   #6
ceantuco
Member
 
Registered: Mar 2008
Location: New York
Distribution: Debian
Posts: 809

Original Poster
Rep: Reputation: 88
Question ???

Quote:
Originally Posted by saagar View Post
KISS
???
 
Old 01-07-2009, 02:24 PM   #7
SqdnGuns
Senior Member
 
Registered: Aug 2005
Location: Pensacola, FL
Distribution: Slackware64® Current & Arch
Posts: 1,092

Rep: Reputation: 174Reputation: 174
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, 08:10 AM   #8
ceantuco
Member
 
Registered: Mar 2008
Location: New York
Distribution: Debian
Posts: 809

Original Poster
Rep: Reputation: 88
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 12:09 PM
Is it OK to delete everything in /tmp? forrest44 Slackware 12 11-15-2005 10:47 PM
How do I delete /tmp partition? akihandyman Mandriva 4 08-08-2004 02:38 PM
Can I delete everything in the /tmp directory? BajaNick Linux - General 5 07-04-2004 01:35 PM
Delete all in /tmp ??? shreev Slackware 5 08-07-2003 04:12 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 08:51 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
Open Source Consulting | Domain Registration