The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
Google UNIX.COM



Thread: list files
View Single Post in UNIX Forums - Click on the Thread or Permalink to View Entire Thread -->
  #4 (permalink)  
Old 06-20-2005
vino's Avatar
vino vino is online now
Supporter (in vino veritas)
 

Join Date: Feb 2005
Location: Bangalore, India
Posts: 2,663
Quote:
Originally Posted by avadhani
hi,
Above command list all files , but all output is passed as one argument to command.
Try this.
Code:
 find /parent/dir/to/search -name '*.[c|cpp|h]' -exec ls -l {} \;
Quote:
Originally Posted by avadhani
and also output has full path of file. I want only filename and comand should be executed on each filename.

Thanks
Yes the output will have filename. That is because, you are searching for files which are inside the /parent/dir/to/search directory. The find returns the path to that file with reference to /parent/dir/to/search.

If you need only the filename on each of the find result, use basename for each result that is thrown.

Code:
 find /parent/dir/to/search -name '*.[c|cpp|h]' -exec basename {} \;
Vino
Reply With Quote