How to remove/delete executable files (aka files without extension) only

you can run

find . -perm +100 -type f -delete

Here you go:

ls | grep -v "\." | xargs rm

The grep -v says "only allow filenames that don't contain a dot", and the xargs rm says "then pass the list of filenames to rm".


Use the find. What you want is this:

find . -type f -executable -exec rm '{}' \;

Removing everything without an extension can also be done:

find . -type f -not -iname "*.*" -exec rm '{}' \;

The former option does not delete the Makefile, and is thus to be preferred. I think kcwu's answer shows a nice way to improve the above using the -delete option :

find . -type f -executable -delete
find . -type f -not -iname "*.*" -delete

Edit: I use GNU findutils find, version 4.4.0, under Ubuntu 8.10. I was not aware the -executable switch is so uncommon.

Tags:

Linux

Unix

C++

File