Recursive chmod only folders or only files via script or nautilus menu?
Here's a script you can call by passing the mode as the first argument and one or more directory names as subsequent arguments. Under Linux, if you don't pass any directory name, it'll be as though you passed .
(the current directory). Name this script rchmodf
, make it executable (chmod a+rx /path/to/rchmodf
) and put it somewhere on your $PATH
.
#!/bin/sh
mode=$1; shift
find "$@" -type f -exec chmod "$mode" {} +
Explanations: mode=$1; shift
sets the variable mode
to the first argument of the script and removes that first argument from the list. "$@"
expands to the list of all arguments.
If you like, you can make a script that accepts both a directory mode and a file mode.
#!/bin/sh
dir_mode=$1; shift
file_mode=$1; shift
find "$@" -type d -exec chmod "$dir_mode" {} + -o -type f -exec chmod "$file_mode" {} +
Note that 744 isn't a useful file mode; 644 (user-writable and world-readable) and 755 (also world-executable) are much more common. Also, changing every file in a tree to be executable or not to be executable is rarely useful; you'll probably want to call this script with arguments like +rX
(capital X
, to set the executable bit only for directories and for files that are already executable). In fact, the X
symbolic mode is probably what you were after with these scripts: chmod -R +rX .
.
With bash or zsh, there's another way to act recursively but on directories only. For bash, you need version 4 and to run shopt -s globstar
first.
chmod a+rx **/*/
In zsh, you can act on files only by suffixing (.)
: chmod a+r **/*(.)
.
I'll pass on the Nautilus question.