Removing executable flag from text files

If you ever shared code repository with people who use Windows, you might notice text files with set executable flag. Such files are a little annoying. When you do a directory listing you suddenly see a lot of programs. When you look at those programs, it turns out they are merely data text files or C++ source code. Since Windows doesn’t distinguish between executable and non-executable files in any other way than the *.exe extension, Windows guys are likely to commit such files unwittingly.

Here’s a line in shell that will help you. Give it a file name extension (say, *.txt) and it will find all the executables with that name and fix them.

find . -name '*.txt' -perm /u+x,g+x,o+x \
-exec chmod a-x {} \;

You can alter the *.txt part, specifying any extension you want. You might want to look for all the *.cpp, *.hpp, *.java, etc., files.

To find out if there are any other files that you might want to correct, try the following line. It will display all executable files:

find . -type f -perm /u+x,g+x,o+x


If you use Subversion for your project, the above method will not work, because in Subversion, the executable flag is stored as a property. Here’s the same script that will deal with a local copy of code pulled from Subversion:

find . -name '*.txt' -perm /u+x,g+x,o+x \
-exec svn pd svn:executable {} \;