Can anyone guide, how to implement this linux command into a bash script
df --local -P | awk {'if (NR!=1) print $6'} | xargs -I '{}' find '{}' -xdev -type d -perm -0002 2>/dev/null | xargs chmod a+t
Can anyone guide, how to implement this linux command into a bash script
df --local -P | awk {'if (NR!=1) print $6'} | xargs -I '{}' find '{}' -xdev -type d -perm -0002 2>/dev/null | xargs chmod a+t
Put this in a file, add a shell shebang on 1st line:
#!/bin/sh
df --local -P |
awk '{if (NR!=1) print $6}' |
xargs -I '{}' find '{}' -xdev -type d -perm -0002 2>/dev/null |
xargs --no-run-if-empty chmod a+t
Under bash, I would write this something like:
#!/bin/bash
{ read foo; mapfile -t mpoints;} < <(df --local -P)
TEXTDOMAIN=libc
exec 2> >(exec grep -v '^find: .*'$"Permission denied"\$ >&2)
find "${mpoints[@]#*% }" -xdev -type d -perm -0002 -exec chmod a+t {} +
Short, quick and efficient!
Explanation:
read foo just whipe header line of df outputmapfile -t take rest of df output into $mpoint array, (-t remove a trailing newline).exec ... {} ... + will do approx same job than using xargs.exec 2>... >&2 will silently delete lines matching regex in STDERR.TEXTDOMAIN=libc and $"Permission denied" will localize message to make this script work in many languages.