Last active
January 26, 2016 21:52
-
-
Save StefanHamminga/a668ce90af594e373278 to your computer and use it in GitHub Desktop.
Bash script to detect whether two paths/files are in the same file system
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
MOUNTS=`cat /proc/mounts | cut -d ' ' -f 2 | sort | uniq | tr '/' '\\/'` | |
IFS=$'\n' | |
what_fs() { | |
for MOUNT in ${MOUNTS}; do | |
readlink -f $1 | grep -o "^${MOUNT}" | |
# echo -e "$1" | |
# echo -e "${MOUNT}" | |
done | |
} | |
if [ $# -ne 2 ]; then | |
echo "Please provide exactly 2 arguments" | |
exit 2 | |
fi | |
if [ ! -e "$1" ]; then | |
echo "File not found: $1" | |
exit 2 | |
fi | |
if [ ! -e "$2" ]; then | |
echo "File not found: $2" | |
exit 2 | |
fi | |
FS1=$(what_fs $1 | tail -n 1) | |
FS2=$(what_fs $2 | tail -n 1) | |
# echo -e "FS for '${1}': ${FS1}" | |
# echo -e "FS for '${2}': ${FS2}" | |
if [ "${FS1}" = "${FS2}" ]; then | |
echo "Same file system" | |
exit 0 | |
else | |
echo -e "Different file system on ${FS2}" | |
exit 1 | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment