Remove executable permissions, while preserving directories.

Every time I copy something from an exfat formatted USB stick, I keep on having to search for this simple one liner…

As exfat doesn’t allow for permissions, when you copy directories back onto your hard drive, in order that the directory structure will work as intended, all the files are given executable permissions. Directories use the executable flag to signal whether the directory can be entered.

Odd’s on there’s few actual executable files in the hierarchy, so often you just want to recursively remove the executable permission on all the files. But doing this will break all the directories, the simple answer is to use find to do the recursion instead of chmod

find -type f -exec chmod -x {} \;

The type parameter f filters for files, so directories are skipped every time chmod is executed. The {} denotes a placeholder where the file name should go, so find knows where the command ends a semicolon is used, but this must be escaped hence the forward slash, using the semicolon means the command is run individually for each filename. If you wanted all the filenames combined and the command run only once, you can use + to signal the end of the command (which doesn’t need escaping)

Leave a Reply

Your email address will not be published.