logo

utils-std

Collection of commonly available Unix tools git clone https://anongit.hacktivis.me/git/utils-std.git

df.sh (1079B)


  1. #!/bin/sh
  2. # SPDX-FileCopyrightText: 2017 Haelwenn (lanodan) Monnier <contact+utils@hacktivis.me>
  3. # SPDX-License-Identifier: 0BSD
  4. WD=$(dirname "$0")
  5. target="${WD}/../cmd/df"
  6. plans=7
  7. . "${WD}/tap.sh"
  8. # stderr ignored because not all filesystems allow statvfs from a normal user.
  9. # For example tracefs aka "/sys/kernel/debug/tracing" on Linux.
  10. t_df_l1() {
  11. "$target" "$@" 2>/dev/null | head -n 1
  12. }
  13. t_cmd posix 'Filesystem 512-blocks Used Available Capacity Mounted on
  14. ' t_df_l1 -P
  15. t_cmd posix_1k 'Filesystem 1024-blocks Used Available Capacity Mounted on
  16. ' t_df_l1 -Pk
  17. set -o pipefail
  18. t_df_posix_cols() {
  19. "$target" "$@" 2>/dev/null | sed -n '2,$p' | { grep -vE '[^ ]+ (-|[0-9]+) (-|[0-9]+) (-|[0-9]+) (-|[0-9]+%) [^ ]+$'; return 0; }
  20. }
  21. t_cmd posix_cols '' t_df_posix_cols -P
  22. t_cmd posix_cols_k '' t_df_posix_cols -Pk
  23. t_cmd posix_cols_a '' t_df_posix_cols -Pa
  24. t_cmd posix_cols_ak '' t_df_posix_cols -Pak
  25. t_df_rootfs() {
  26. "$target" "$@" 2>/dev/null | sed -n '2,$p' | { grep -vE '^[^ ]+ [0-9]+ [0-9]+ [0-9]+ [0-9]+% /$'; return 0; }
  27. }
  28. t_cmd posix_cols_rootfs '' t_df_rootfs -P /