to grep and rm including all subdirectories


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers to grep and rm including all subdirectories
# 1  
Old 10-10-2000
Question

Is there a way to grep a word pattern in all files under all subdirectories?

Similar question with rm. To remove files with certain extension in all subdirectories?

Thanks to all who reply!
# 2  
Old 10-10-2000
Yes, of course. The way I do this is with the find() command. For example, to remove all mp3 files in a directory and all subdirectories;

find * -regex '.*\.mp3' -exec rm {} ;

This will recursively find all files and use the regular
expression matching any string up to the final .mp3
and then remove that file (might want to check the regex
pattern, I'm doing this without checking Smilie

Another example. You want to change the owner and group
of all files and subfiles:


find * -exec chown admin.users {} \;

My suggestion is that you do a 'man on find' and read about using the -regex and -exec flags. Fun and powerful stuff!


 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Sendmail including gif's ?

My department uses an outlook mail merge to send login information to multiple users who request access. I would like to use sendmail for obvious reasons. I copied a sample email source, with all the disgusting html formatting from outlook, and can successfully send emails almost exactly as I did... (0 Replies)
Discussion started by: MaindotC
0 Replies

2. Shell Programming and Scripting

Zip all the files including directories - subdirectories

Hi, Is is possible to zip a folder and all its contents within the folder ( including sub-directories and files) into a zip file? and can regain the same structure if unzipped? Thanks (6 Replies)
Discussion started by: rudoraj
6 Replies

3. AIX

including netsnmp with rc scripts

Hi Admins, I have configured net-snmp with my aix 5.3 server. how to add the same in rc scripts,so that net-snmp will start automatically post server reboot. As per now , i have to start snmp manually after server reboot. Thanks in advance newaix (0 Replies)
Discussion started by: newaix
0 Replies

4. Shell Programming and Scripting

Grep a string from input file and delete next three lines including the line contains string in xml

Hi, 1_strings file contains $ cat 1_strings /home/$USER/Src /home/Valid /home/Review$ cat myxml <projected value="some string" path="/home/$USER/Src"> <input 1/> <estimate value/> <somestring/> </projected> <few more lines > <projected value="some string" path="/home/$USER/check">... (4 Replies)
Discussion started by: greet_sed
4 Replies

5. Shell Programming and Scripting

Goto each directory and subdirectories and grep the required pattern

Hi All, I need your help in finding pattern from files present in different directories. I need to search for a pattern "xyz" from "*.txt" files which are present in different levels of directories as shown. example ------- dir1/subdir1/file.txt dir2/subdir2/subsubdir2/file.txt... (5 Replies)
Discussion started by: imas
5 Replies

6. Programming

Error while including libraries

Hi All, When i am trying to include graphics.h ,dos.h and conio.h, its giving error as follows: pgm.c:2:17: dos.h: No such file or directory pgm.c:3:22: graphics.h: No such file or directory pgm.c:4:19: conio.h: No such file or directory Whereas stdio.h, stdlib.h and time.h gets... (3 Replies)
Discussion started by: jisha
3 Replies

7. UNIX for Dummies Questions & Answers

Including files

Hi, Is it possible to include files (print with EOF, sort of like ssi) in perl/cgi? Thanks (1 Reply)
Discussion started by: marringi
1 Replies

8. Programming

Error different when including a printf

Hi I am trying to debug a code by including prinf . TO some extended it shows error at one point . If i include an extra printf it is showing at different point . Can anybody please let em know why it is happening .. Thaks, Arun (1 Reply)
Discussion started by: arunkumar_mca
1 Replies

9. Shell Programming and Scripting

PERL: including files

I am wondering how I can include external files in a perl script. I'm currently working on a website, and I'd like to put my menu items in a subroutine for example, and put that in another file such as menu.pl. That way, I can call the subroutine from each page (such as news.pl), and if I want to... (2 Replies)
Discussion started by: LNC
2 Replies

10. Solaris

grep a string on all files in the subdirectories

Hi all, I would want to find a string 'abc' on all files which is located under a directory. But inside the directory there are subdirectories, so how can I find whether 'abc' exists on all files in the subsequent subdirectories? Thanks. (4 Replies)
Discussion started by: *Jess*
4 Replies
Login or Register to Ask a Question