LinuxQuestions.org
Have you listened to LQ Radio?
Go Back   LinuxQuestions.org > Forums > Linux > Linux - General
User Name
Password
Linux - General This 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
 
Thread Tools Search this Thread
Old 02-15-2005, 03:22 PM   #1
Arodef
Member
 
Registered: Apr 2004
Distribution: Centos, Fedora
Posts: 103
Thanked: 0
How to do recursive file delete using specifier (*.tmp) from nested directories?


[Log in to get rid of this advertisement]
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 03:33 PM..
Arodef is offline     Reply With Quote
Old 02-15-2005, 03: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
Thanked: 0
Another solution FFR:

find /path -name \*.tmp | xargs rm
sigsegv is offline     Reply With Quote
Old 02-15-2005, 03:39 PM   #3
jailbait
Guru
 
Registered: Feb 2003
Location: atop the Blue Ridge
Distribution: Debian Lenny, CentOS 5.2
Posts: 7,251
Thanked: 31
"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 03:40 PM..
jailbait is offline     Reply With Quote
Old 11-11-2009, 08:49 AM   #4
vantoora
LQ Newbie
 
Registered: Oct 2007
Posts: 4
Thanked: 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.
windows_xp_2003 vantoora is offline     Reply With Quote

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


All times are GMT -5. The time now is 03:40 PM.

Main Menu
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.
Advertisement
Oracle Magazine contains technology strategy articles, sample code, tips, Oracle and partner news, how to articles for developers and DBAs, and more. Click Here to receive a complimentary subscription courtesy of LQ.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
RSS2  LQ Podcast
RSS2  LQ Radio
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: @linuxquestions
Open Source Consulting | Domain Registration