LinuxQuestions.org
Share your knowledge at the LQ Wiki.
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 02-15-2005, 02:22 PM   #1
Arodef
Member
 
Registered: Apr 2004
Distribution: Centos, Fedora
Posts: 125

Rep: Reputation: 17
How to do recursive file delete using specifier (*.tmp) from nested directories?


I basically want to delete file matching a wildcard from a directory and all its subdirectories.

Examples:

mydelete *.tmp mydir/


So all the files ending with *.tmp in mydir/ and its subdirs would be deleted. How can I do this?


EDIT:
n/m, found the solution:

rm `find /home/user/path -name '*.tmp'`


Last edited by Arodef; 02-15-2005 at 02:33 PM.
 
Old 02-15-2005, 02:35 PM   #2
sigsegv
Senior Member
 
Registered: Nov 2004
Location: Third rock from the Sun
Distribution: NetBSD-2, FreeBSD-5.4, OpenBSD-3.[67], RHEL[34], OSX 10.4.1
Posts: 1,197

Rep: Reputation: 47
Another solution FFR:

find /path -name \*.tmp | xargs rm
 
Old 02-15-2005, 02:39 PM   #3
jailbait
LQ Guru
 
Registered: Feb 2003
Location: Virginia, USA
Distribution: Debian 12
Posts: 8,337

Rep: Reputation: 548Reputation: 548Reputation: 548Reputation: 548Reputation: 548Reputation: 548
"I basically want to delete file matching a wildcard from a directory and all its subdirectories."

find mydir/ -iname "*.tmp" -exec rm {} \;

See man find.

------------------------------
Steve Stites

Last edited by jailbait; 02-15-2005 at 02:40 PM.
 
Old 11-11-2009, 07:49 AM   #4
vantoora
LQ Newbie
 
Registered: Oct 2007
Posts: 6

Rep: Reputation: 0
Delete file recursively

Dear all,
I have a similar problem with deleting some files recursively but more complex and I have not yet found a solution if anyone here can help me.

So my problem is this :
Suppose I have a root folder named 'vantoora' and have many subfolders inside 'eg. vantoora1, vantoora2... vantooraN'.
Inside of each subfolders there are two folders named 'new' and 'old' which contain many files each.

vantoora
|_ vantoora1
|_ new
|_ file1.txt
|_ old
|_ file1.txt
|_ file2.txt
|_ vantoora2
|_ new
|_ file1.txt
|_ file2.txt
|_ old
|_ file2.txt
:...
:...
|_ vantooraN
|_ new
|_ file1.txt
|_ file2.txt
|_ old
|_ file1.txt
|_ file2.txt

What I want to do is that search recursively for 'new' and/or 'old' and then delete every files inside those folders.

$ cd vantoora
$ vantoora > ls
$ vantoora > vantoora1 vantoora2 ... vantooraN

What I have done is following command but don't want to delete :
$ find -name 'new' | xargs ls "$1" /* to list all files inside all new folder */

tried :
$ find -name 'new' | xargs ls "$1" | xargs rm -f
but returned error something like : ls: cannot access ./vantoora/vantoora1...

All suggestions are welcome.
Thanks for you reply.
 
  


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
[SOLVED] FTP: recursive chmod (separate for directories and files) mgmax Linux - Software 11 01-29-2011 08:06 AM
Is it OK to delete everything in /tmp? forrest44 Slackware 12 11-15-2005 10:47 PM
cleaning up tmp directories markus1982 Linux - General 7 09-19-2004 11:57 AM
Create file using 'touch ./tmp.$$', file tmp.3941 is created, why? huangyanfeng Linux - General 1 04-13-2004 03:36 AM
Delete all in /tmp ??? shreev Slackware 5 08-07-2003 04:12 PM

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

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