簡體   English   中英

如何在Linux上檢測慢速文件系統?

[英]How can I detect slow filesystems on Linux?

對於我的shell配置,我想知道我是否在慢速目錄中(例如sshfs或cifs掛載)。

這使我可以跳過一些操作,例如通過Zsh的vcs_info查找存儲庫中的vcs_info

我想出了以下函數,如果df -T不可用(例如,在busybox系統上),它將首先嘗試df -T並通過mount查找文件類型:

_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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM