LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 02-03-2011, 01:22 PM   #1
ddebbie90
LQ Newbie
 
Registered: Feb 2011
Posts: 17

Rep: Reputation: 0
how can i find the files with extension .h or .c with bash scripts?


As i say in the subject i want to find all files with .h or .c extension and print them on the screen. How can i do it with bash script programming??
 
Old 02-03-2011, 01:28 PM   #2
goossen
Member
 
Registered: May 2006
Location: Bayern, Germany
Distribution: Many
Posts: 224

Rep: Reputation: 41
Code:
find / -name '*.h' -or -name '*.c'

Last edited by goossen; 02-03-2011 at 01:31 PM. Reason: typo
 
1 members found this post helpful.
Old 02-03-2011, 01:29 PM   #3
goossen
Member
 
Registered: May 2006
Location: Bayern, Germany
Distribution: Many
Posts: 224

Rep: Reputation: 41
Replace "/" by the path if is needed. E.g.: /var, /usr/src/
 
Old 02-03-2011, 01:29 PM   #4
crts
Senior Member
 
Registered: Jan 2010
Posts: 2,020

Rep: Reputation: 757Reputation: 757Reputation: 757Reputation: 757Reputation: 757Reputation: 757Reputation: 757
Try this
find /path/to/folder -name '*.c' -o -name '*.h'
 
Old 02-03-2011, 01:33 PM   #5
ddebbie90
LQ Newbie
 
Registered: Feb 2011
Posts: 17

Original Poster
Rep: Reputation: 0
goossen thank you very much! the first one works perfect!
 
Old 02-03-2011, 08:51 PM   #6
kurumi
Member
 
Registered: Apr 2010
Posts: 228

Rep: Reputation: 53
Ruby(1.9+)

Code:
$ ruby -e 'Dir["/path/**/*.{h,c}"].each {|x| puts x}'
 
  


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



Similar Threads
Thread Thread Starter Forum Replies Last Post
Need bash script to list files, drop extension and dump to file talwar_ Programming 10 06-03-2011 09:18 AM
[SOLVED] How can I find the total disk space used by all files with the same extension (*.dat) respex Linux - Newbie 5 12-04-2009 06:38 AM
Bash script: symbolic linking all files with same extension in a directory Katachi Programming 1 12-25-2006 09:42 AM
bash script to sort files by extension otheralex Programming 7 08-19-2005 02:40 AM
bash scripts and running .sh files xviddivxoggmp3 Programming 9 08-14-2004 05:33 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

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