Solution1: Using @kdave's suggestions:
is_btrfs_subvolume() { local dir=$1 [ "$(stat -f --format="%T" "$dir")" == "btrfs" ] || return 1 inode="$(stat --format="%i" "$dir")" case "$inode" in 2|256) return 0;; *) return 1;; esac }
Solution2: What I used before (only one call, but probably fragile):
is_btrfs_subvolume() { btrfs subvolume show "$1" >/dev/null 2>&1 }
EDIT: Fixed and replaced list with show , since list behavior would not respond correctly in any regular btrfs directory.
EDIT2: since @kdave did not post the full version of his excellent answer, I added it to my answer.
vaab source share