Arg list too long | Unix Linux Forums | UNIX for Dummies Questions & Answers

  Go Back    


UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

Arg list too long

UNIX for Dummies Questions & Answers


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 01-31-2013
tkhan9 tkhan9 is offline
Registered User
 
Join Date: Jun 2011
Last Activity: 23 July 2013, 2:25 AM EDT
Posts: 6
Thanks: 3
Thanked 0 Times in 0 Posts
Arg list too long

Hello All,
I am trying to find a file name with .sh exention from a list of .dat files inside a directory.

find /app/folder1/* -name '*.dat'| xargs grep '.sh'
ksh: /usr/local/bin/find: arg list too long

Please help me finding the command.

Thanks

Sponsored Links
    #2  
Old 01-31-2013
Yoda's Avatar
Yoda Yoda is offline Forum Advisor  
Jedi Master
 
Join Date: Jan 2012
Last Activity: 30 July 2014, 7:43 PM EDT
Location: Galactic Empire
Posts: 3,358
Thanks: 230
Thanked 1,190 Times in 1,123 Posts
Try running:

Code:
find /app/folder1/* -name '*.dat' -type f -exec grep '.sh' {} \;

Sponsored Links
    #3  
Old 01-31-2013
tkhan9 tkhan9 is offline
Registered User
 
Join Date: Jun 2011
Last Activity: 23 July 2013, 2:25 AM EDT
Posts: 6
Thanks: 3
Thanked 0 Times in 0 Posts
Thanks - but that does not work either.
Maybe the ncargs value is too low on my system.

ncargs 6 ARG/ENV list size in 4K byte blocks True
    #4  
Old 01-31-2013
Don Cragun's Avatar
Don Cragun Don Cragun is offline Forum Staff  
Moderator
 
Join Date: Jul 2012
Last Activity: 30 July 2014, 9:25 PM EDT
Location: San Jose, CA, USA
Posts: 4,197
Thanks: 164
Thanked 1,430 Times in 1,213 Posts
I assume that bipinajith's proposed solution will still fail because /app/folder1/* is expanding to a list of arguments too long to process. The following should avoid that problem and be MUCH more efficient:

Code:
find /app/folder1 -name '*.dat' -type f -exec grep '.sh' {} +

Note, however, that if your .dat files are binary files (rather than text files) grep might not work. (The standards only specify the behavior of grep when its input files are text files.)

Also note that if grep is called with only one file operand, the name of the file in which the line is found will not be printed; just the contents of the matching line. If your .dat files are text files and you want the name of the file to be printed as well as the matched lines even if there is only one file operand, add /dev/null as another file operand. If you only want the names of matching files, but don't need to see the matched lines use the -l (letter ell; not digit 1) option.

And note that the pattern specified by '.sh' is a basic regular expression will match the two characters sh as long as they are not the 1st two characters on a line. If you want to match the three characters .sh , you need to add the -F option, use the obsolescent fgrep utility instead of grep, or escape the period in the BRE.
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
arg list too long Zenwork Shell Programming and Scripting 2 10-08-2008 03:06 PM
ls -t arg list too long CSU_Ram UNIX for Dummies Questions & Answers 4 05-05-2005 10:19 AM
arg list too long encrypted UNIX for Advanced & Expert Users 8 11-12-2004 05:38 AM
egrep and Arg list too long kingo UNIX for Dummies Questions & Answers 6 05-22-2002 11:52 AM
arg list too long vingupta UNIX for Dummies Questions & Answers 5 08-02-2001 11:43 PM



All times are GMT -4. The time now is 11:20 PM.