#! /bin/bash # Respond to the question : if a new file is created, this will be on which block device ? # Input arg 1 : path (file) # Outpout : path (block device) set -euo pipefail IFS=$' \t\n' export LC_ALL=C NEW_FILE="$1" # check if directory exists dir_exists() { if [ -d "$1" ] then return 0 else return 1 fi } get_parent_dir() { local CHEMIN="$1" while ! "$(dir_exists "$CHEMIN")" do CHEMIN=$(dirname "$CHEMIN") done echo "$CHEMIN" } get_device() { df -lP "$(get_parent_dir "$NEW_FILE")" |awk 'NR==2{print $1}' } get_device "$(get_parent_dir "$NEW_FILE")"