LinuxQuestions.org
Share your knowledge at the LQ Wiki.
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 07-07-2010, 01:34 AM   #1
sumedh_bhogle
LQ Newbie
 
Registered: Jul 2010
Posts: 3

Rep: Reputation: 0
Help with find command


Hi ther,

I wanted formated output of all the files under a particular directory. I am trying to use find.

Something like
find -P ./ -type f -name '*.cpp' -printf "%p "

I want all the files with specific extension like .c .cpp .h to be printed out separated by space. One more thing i want is absolute path names instead of relative.

Hoping for some help...
Thanks,
 
Old 07-07-2010, 02:03 AM   #2
timmeke
Senior Member
 
Registered: Nov 2005
Location: Belgium
Distribution: Red Hat, Fedora
Posts: 1,515

Rep: Reputation: 61
Getting absolute file names will depend on the folder you want "find" to search. If you put "./" as in your example, output will be with relative paths. Try using the full path of the current directory (or ${PWD} for simplicity).

Code:
find ${PWD} -type f -name '*.cpp' -printf "%p "
To add also .c and .h files (and maybe .hpp?), try combining multiple -name options using the "-o" or "-or" operator.

Hint: to make code appear more clearly, put it inbetween CODE tags.

Last edited by timmeke; 07-07-2010 at 02:05 AM.
 
1 members found this post helpful.
Old 07-07-2010, 02:03 AM   #3
rical
LQ Newbie
 
Registered: Jun 2010
Posts: 13

Rep: Reputation: 1
Specify the absolute path in your find command and It will be printed.

Code:
find -P /path/to/root -type f -name '*.cpp' -printf "%p "
Did not get if you wanted something more, it seams to do what you want.

Hope this helps.
 
1 members found this post helpful.
Old 07-07-2010, 06:04 AM   #4
sumedh_bhogle
LQ Newbie
 
Registered: Jul 2010
Posts: 3

Original Poster
Rep: Reputation: 0
Thanks timmeke, rical

works well..

@timmeke -or thing is not working..
 
Old 07-07-2010, 06:40 AM   #5
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,006

Rep: Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191
How about:
Code:
find ${PWD} -type f -regex '.*\.[ch]\(pp\)?'
 
1 members found this post helpful.
Old 07-08-2010, 12:07 AM   #6
sumedh_bhogle
LQ Newbie
 
Registered: Jul 2010
Posts: 3

Original Poster
Rep: Reputation: 0
@grail Cool regex zakas!!(regex rocks)
are u really creating a distro... i would like to be part of it...
 
  


Reply

Tags
comands, linux



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
Find/grep command to find matching files, print filename, then print matching content stefanlasiewski Programming 9 06-30-2016 05:30 PM
Find/grep/wc command to find matching files, print filename and word count dbasch Linux - Newbie 10 09-14-2009 05:55 PM
Single find command to find multiple files? thok Linux - Newbie 7 01-31-2009 04:45 PM
Using a single "Find" Command to find files bases on multiple criteria roboxooo Linux - Newbie 6 01-15-2009 04:13 AM
can't find my find command! how to replace? dave247 Debian 4 11-19-2008 10:51 AM

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

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