This answer attempts to address yves's following preoccupations:
I would prefer not to have an alias for every option combination (1)
and
although it shows the '/' in red (2)
and (3)
add an important piece of info to the varying output, which is df
's header line that changes according to the supplied flags.
(1) You need function
, because by definition it takes arguments. And, it is very simple to define and use as you'll find out below.
(2) the red /
is produced by grep --color
, which is a common alias to grep
itself (you can check that by running alias
).
code
function df1
{
df $* | sed -n '1p;/^\//p;'
}
The newlines above are intended to improve readability, you can replace them by space.
Copy and paste this snippet directly to an interactive bash session or, even better, append it to your ~/.bashrc
.
Example usage
$ df1
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/disk1 487358464 316093104 171009360 65% /
/dev/disk2 524032 302620 221412 58% /Volumes/Packer
$ df1 -hT
Filesystem Type Size Used Avail Use% Mounted on
/dev/disk1 hfs 465G 302G 164G 65% /
/dev/disk2 hfs 512M 296M 217M 58% /Volumes/Packer
$ df1 -hT .
Filesystem Type Size Used Avail Use% Mounted on
/dev/disk1 hfs 465G 302G 164G 65% /
What it does
The function df1
calls df
with whatever arguments you pass it and pipes (|
) the output to sed
, which is invoked with -n
to suppress automatic printing of the pattern space. The rest expresses the sed "scripts", two actually:
- the script
1p
prints the 1st line, which in our case is df
's header (I use the same for ps
piping),
- the script
/^\//p
matches any line starting with /
, then prints it
;
separates the 2 sed scripts