Help answer threads with 0 replies.
Go Back > Forums > Linux Forums > Linux - General
User Name
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.


  Search this Thread
Old 02-15-2005, 02:22 PM   #1
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.


mydelete *.tmp mydir/

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

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
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: 46
Another solution FFR:

find /path -name \*.tmp | xargs rm
Old 02-15-2005, 02:39 PM   #3
LQ Guru
Registered: Feb 2003
Location: Blue Ridge Mountain
Distribution: Linux Mint 17, Debian 8
Posts: 7,865

Rep: Reputation: 311Reputation: 311Reputation: 311Reputation: 311
"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
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.

|_ 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.


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 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 > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 01:30 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration