rm all executables

Posted:
in Genius Bar edited January 2014
Hi all





I move some source code from an SGI to the PowerBook. Now I need to compile but all the old object files and executables are still there. What's the trick to delete all files that are set to execute? I looked in the rm and find man pages to see if there was a way to filter on mode but I don't see it.





Any help?

Comments

  • Reply 1 of 3
    wmfwmf Posts: 1,164member
    Did you try `make clean`? (Assuming there's a makefile.)



    find -perm ought to do it.
  • Reply 2 of 3
    willoughbywilloughby Posts: 1,457member
    I'm pretty sure there isn't an exact command to remove all executables, but you could write a quick shell script to do it.



    Basically this command will list all the files that are executables in a given directory:



    ls -al | egrep "^-..x"



    This one will do the same, but only print the files name:



    ls -al | egrep "^-..x" | awk '{ print $9 }'



    So in a shell script, do a loop that iterates through each line (which is actually each file name) and issues the rm command on that files name based on the output from the above command.



    If I could remember the "for" syntax in shell scripting I'd do it for you...but its been awhile.
  • Reply 3 of 3
    1337_5l4xx0r1337_5l4xx0r Posts: 1,558member
    ls -al | egrep "^-..x" > list.txt && for i in `cat list.txt`; do rm -f $i; done
Sign In or Register to comment.