[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: df wishlist
From: |
L A Walsh |
Subject: |
Re: df wishlist |
Date: |
Sat, 16 Mar 2019 13:23:30 -0700 |
User-agent: |
Thunderbird |
On 3/16/2019 9:07 AM, Bruce Dubbs wrote:
> It would be helpful to add a --terse option to df such that a user could
> do something like:
>
> DF=$(df -k --terse --output=used $PWD)
>
> Right now I see no method of omitting the header or to collapse the
> spaces between values to a single space. This can be done of course
> with tools like awk, cut, sed, grep, tail, etc, but would be a lot
> cleaner if done inside df.
>
Would this work? it is inside "df" (sorta) ;-):
df ()
{
if [[ ${-//[^i]/} == i ]]; then
declare -i x=0;
command df -k --output=source,used "$@" | while read src used; do
((x++)) && printf "%s %s\n" "$src" "$used";
done;
else
command df "$@";
fi
}
*or*, all on 1 line:
df() { if [[ ${-//[^i]/} == i ]]; then declare -i x=0;command df -k
--output=source,used "$@"|while read src used; do ((x++)) && printf "%s
%s\n" "$src" "$used" ; done ; else command df "$@" ; fi ; }
-----
So it will only take 1 line in your history; :-)
It's a tad longer than minimum, as it tests to see if it is interactive
and does your format for interactive use, but if the function
was defined in a script, the function will call 'df' w/no filtering
to give "standard output".
If you define your functions in bash_profile and in bashrc,
it will usually work the way you want it to... ;-) Though in
some cases util mods need more than a function wrapper.
Anyway this should give you the directories you listed on the cmd line
followed by size in 'KB':
> df /home /backup
/dev/Data/Home 1350442108
/dev/mapper/Backup-Backup 11203606872
(you sure you didn't want to include -h
along with -k, though you can pass it on the cmd line:
> df -h /home /backup
/dev/Data/Home 1.3T
/dev/mapper/Backup-Backup 11T
-l