简体   繁体   中英

How can I detect slow filesystems on Linux?

For my shell configuration I want to know if I am on a slow directory (eg sshfs or cifs mount).

This allows me to skip some actions, like looking for changes in repositories via Zsh's vcs_info .

I've came up with the following function, which first tries df -T and looks up the file type via mount , if df -T is not available (eg on busybox systems):

_is_slow_file_system() {
  df_T=$(df -T . 2>/dev/null) || true
  if [[ $df_T == '' ]]; then
    # 'df -T' might not be available (busybox, diskstation).
    # 'stat -f' does not detect cifs (type UNKNOWN).
    # fs_type=$(stat -f . | grep -o 'Type:.*' | cut -f2 -d\ )
    mount_point="$(df . | awk 'END {print $NF}')"
    fs_type=$(mount | awk '$3 == "'$mount_point'" { print $5 }')
  else
    fs_type=$(echo $df_T | tail -n1 | tr -s ' ' | cut -f2 -d\  2>/dev/null)
  fi

  case $fs_type in
    (sshfs|nfs|cifs|fuse.bup-fuse) return 0 ;;
    (*) return 1;;
  esac
}

很简单,只需在终端中运行

cat /proc/filesystems

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM