0

I know this can be done because I've done it before on previous servers but I forgot how and web searches did not come up with the result.

I know what tmpfs is and that you should not remove it. What I want to do is to hide it. Basically I did something like modifying the output so that when you ran the df command it would exclude tmpfs from the output, but I forget exactly how I did it.

Example output: enter image description here

How can I hide the tmpfs from the df output? Again, not to delete or disable tmpfs, but merely to hide it from the output in ssh. It is annoying to see especially when I add many drives.

UPDATE: I was able to find in my saved files the command which does what I want, but now I need to know how to build this into .bashrc as an alias so that whenever I type:

df -h

it really sends:

df -Th| grep -Ev '(udev|tmpfs)'

edit: ok so I did figure out something. I can't do it for the full df -h, but I can add it for the alias of df, by adding this to .bashrc:

alias df="df -Th| grep -Ev '(udev|tmpfs)'"

ok, the oddest thing happened. After I added this command into .bashrc, now, even when I removed that same line altogether, it has fully modified the df command so that even when I put df -h it still hides all the tmpfs. I'm not sure if this is temporary but I reloaded .bashrc in ssh and still all tmpfs are hidden.

I then discovered the only way to revert it is to add back in this line into .bashrc

alias df="df -Th| grep -Ev '(none)'"

Now df behaves normally again. So, it seems the issue is solved.

4 Answers4

3

The df from GNU coreutils have this option:

  -x, --exclude-type=TYPE -- limit listing to file systems not of type TYPE

You can run df -x tmpfs so you will get this result:

Filesystem     1K-blocks    Used Available Use% Mounted on  
udev             3993228       0   3993228   0% /dev  
/dev/sdb2      113298660 9471544  98025696   9% /  
/dev/sdb1         523244    3484    519760   1% /boot/efi
  • as you can see tmpfs is omitted from the listing.
chutz
  • 7,888
  • 1
  • 29
  • 59
nmr50
  • 31
  • 4
  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Jul 26 '22 at 04:48
  • This is the solution to go. Using '| grep' prevents passing further arguments to 'df' as they would all be taken by grep (e.g. you can't use 'df .' to show info on the current directory's partition), – FedFranz Dec 02 '22 at 14:34
0

The solution is to write in a line to rewrite df. However, this will slightly alter just typing df to really output df -Th which is a more human-readable output.

# remove all tmpfs from all df output (you must use the next info to revert df to behave normally)
alias df="df -Th| grep -Ev '(udev|tmpfs)'"

# to revert df to behave normally, remove the above section and uncomment the below line:
# alias df="df -Th| grep -Ev '(none)'"

I hope this helps someone, because I was annoyed by the tmpfs output that I didn't need to see when checking my df output, because I have many drives on some servers and it's cleaner to look at the many drives and usage which I check often. I was annoyed by the tmpfs for over a year before I solved the issue, so I hope it helps you too.

0
:~$ ssh 192.168.0.19 "df -h | grep -E \"sd[a-z]|vg\""
francois@192.168.0.19's password:
/dev/sda2       464G  130G  335G  28% /
/dev/sdb1       466G  208G  258G  45% /home
/dev/sda1       1.9G  383M  1.4G  22% /boot
:~$ 

I prefer the idea in this case is to think about reversing the question ... output needed lines instead of masking the unneeded ones.... With this method you cannot discover a unexpected/unknown pattern in future.

you can add specific cases in the grep for logical volumes ; nfs and so on of course.

francois P
  • 165
  • 2
  • 12
  • please provide an example because I don't understand your answer. –  Feb 12 '20 at 14:50
  • This is the example in the answer ... I grep what I am looking for ... (/dev/sd[a-z]) because devices are named sd + one letter so I get only the mounted devices and no tmpds nor devtmpfs ... – francois P Feb 12 '20 at 16:47
0

Simple workaround. Create the following one-line script somewhere in your executable path...

df $1 $2 $3 $4 | grep -v tmpfs

I called mine df_override and put it in /usr/bin

Then alias it like this...

# alias df='df_override '

That's it! Now you can use df without losing its switches and it will operate normally, except it won't show the tmpfs mounts.

Gerald Schneider
  • 23,274
  • 8
  • 57
  • 89
Eric
  • 1