Register
It is currently Fri Dec 19, 2014 11:28 pm

Help making script to list all extensionless files


All times are UTC - 6 hours


Post new topic Reply to topic  [ 11 posts ] 
Author Message
 PostPosted: Fri May 07, 2010 10:46 am   

Joined: Wed Nov 26, 2008 7:43 pm
Posts: 50
Location: Texas
I want to make a simple script to list all
files that are executable, many of them
are not *.sh, and are extensionless

any help appreciated,

Ted.


Top
 Profile  
 PostPosted: Fri May 07, 2010 12:59 pm   

Joined: Mon Mar 02, 2009 3:03 am
Posts: 579
find has an -executable test.

you could also do a recursive grep to look for shebang pattern.


Top
 Profile  
 PostPosted: Fri May 07, 2010 1:06 pm   

Joined: Wed Nov 26, 2008 7:43 pm
Posts: 50
Location: Texas
like this
find . -perm 755

but that's not what I want because then I get all files with those permissions.. maybe I really mean extensionless files.. files without the '.'


Top
 Profile  
 PostPosted: Fri May 07, 2010 2:42 pm   

Joined: Mon Mar 02, 2009 3:03 am
Posts: 579
may be:
Code:
find . -type f -executable -regex "[^.]*"


Top
 Profile  
 PostPosted: Fri May 07, 2010 6:26 pm   

Joined: Wed Apr 14, 2010 10:23 am
Posts: 17
If I'm not completely mistaken it could be done like
Code:
-perm -100 -o -perm -010 -o -perm -001

(wich I believe is a good reason for the -executable option)
and
Code:
! -name "*.*"

(regexes are overrated)


Top
 Profile WWW  
 PostPosted: Sun May 09, 2010 11:53 am   

Joined: Wed Nov 26, 2008 7:43 pm
Posts: 50
Location: Texas
I don't get why you guys insist on that -executable option.. that doesn't exist or does it?

find . -type f -executable -regex "[^.]*"
find: -executable: unknown option

find . ! -name '*.*'
Also I'm getting all the .svn output with your last suggestions which is close to what I want, but not quite.. how would I omit the .svn dir from this output.

Ted.


Top
 Profile  
 PostPosted: Sun May 09, 2010 5:14 pm   

Joined: Wed Apr 14, 2010 10:23 am
Posts: 17
I don't know about the -executable option, at least my manpage doesn't list it- Might be a newer version or a completely different find, I simply don't know.

For the .svn directory exclusion: Simply use -prune, it's made for this kind of job. http://mywiki.wooledge.org/UsingFind#A-prune


Top
 Profile WWW  
 PostPosted: Sun May 09, 2010 5:36 pm   

Joined: Mon Mar 02, 2009 3:03 am
Posts: 579
Code:
find --version
find (GNU findutils) 4.4.0
comes with -executable test option.


Top
 Profile  
 PostPosted: Mon May 10, 2010 4:26 am   
Moderator
User avatar

Joined: Thu Oct 11, 2007 7:12 am
Posts: 229
Location: London - UK
if your find does not have -executable then the following would probably be ok, if a little wordy;

Code:
find . -type f -exec bash -c 'if [[ -x "{}" ]]; then echo "{}"; fi' \;


Top
 Profile  
 PostPosted: Mon May 10, 2010 5:00 am   

Joined: Mon Mar 02, 2009 3:03 am
Posts: 579
Hi DarthWavy,

unfortunately, this won't work, because bash doesn't know {}:
Code:
find . -type f -exec bash -c 'if [[ -x "$1" ]]; then echo "$1"; fi' _ {} \;
but still the -perm /mode option is shorter
Code:
find . -type f -perm /111 ! -name "*.*"


Top
 Profile  
 PostPosted: Wed May 12, 2010 3:54 am   
Moderator
User avatar

Joined: Thu Oct 11, 2007 7:12 am
Posts: 229
Location: London - UK
Watael wrote:
Hi DarthWavy,

unfortunately, this won't work, because bash doesn't know {}:
Code:
find . -type f -exec bash -c 'if [[ -x "$1" ]]; then echo "$1"; fi' _ {} \;



I'm a little confused as this is not the line I submitted as an option. If you're going to imply that I said something I didn't then please make it uber so that I look good <):)


Top
 Profile  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 11 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
cron


BashScripts | Promote Your Page Too
Powered by phpBB © 2011 phpBB Group
© 2003 - 2011 USA LINUX USERS GROUP