LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 06-21-2012, 01:21 PM   #1
Cinematography
Member
 
Registered: Apr 2005
Location: Chicago, IL
Distribution: openSUSE 13.1
Posts: 357

Rep: Reputation: 31
Command for deleting file type from a directory and its subdirectories?


I'm looking for a fast way to recursively delete files from a directory. For example: Suppose I wanted to delete all .bak files from /home/bob/, and the subdirectories within bob?

I think I already know the command. Would I type rm -r *.bak /home/bob? I just want to be sure before I try it.
 
Old 06-21-2012, 02:28 PM   #2
netraider
LQ Newbie
 
Registered: Jun 2012
Posts: 12

Rep: Reputation: 0
Hello Cinematography,

I would try this:

# find /home/bob -type f -name "*.bak" -exec rm {} \;

That should take care of it. Run the command without -exec rm {} \;
first, to see what will be removed. If you like what you see, then run the full command.

If you find this helpful, please up my rep. Thanks.

Last edited by netraider; 06-21-2012 at 02:29 PM. Reason: Added a request
 
Old 06-21-2012, 02:30 PM   #3
414N
Member
 
Registered: Sep 2011
Location: Italy
Distribution: Slackware
Posts: 647

Rep: Reputation: 189Reputation: 189
Code:
find /home/bob -type f -name "*.bak" -delete
Same functionality without exec
 
Old 06-21-2012, 05:58 PM   #4
Cinematography
Member
 
Registered: Apr 2005
Location: Chicago, IL
Distribution: openSUSE 13.1
Posts: 357

Original Poster
Rep: Reputation: 31
Thanks!
 
  


Reply



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 On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Limit sudo to only one directory and it's subdirectories by sudoers file lcwilson Linux - Security 2 03-28-2012 03:55 PM
Sort Many Files in Subdirectories into Directories by File Type garyozzy Programming 5 02-15-2011 03:18 PM
[SOLVED] Script to open all subdirectories of a single directory and then run a command (help) Euler2 Linux - Newbie 7 03-24-2010 10:16 PM
Deleting files particular type of file using rm? vxc69 Linux - General 3 05-11-2007 09:47 PM
monitoring file added to a directory / subdirectories abhi_abhijith Programming 4 02-13-2006 07:25 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 08:31 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