Use grep in Mac Terminal
I use Terminal in Mac with the follow开发者_如何学JAVAing command:
df -lak | grep File||disk02
what I want to use this script to get the header of df command (disk space) and the line with disk02 only. I think '|' is a char in grep as or logic. However, since I am using grep in Terminal, the char '|' also means pipe. Therefore I tried to use '||' to avoid piping, but it does not get what I want. Only the header with "File" is back.
Not sure how I can use this script command in Terminal?
df -lak | grep "File\|disk02"
use awk
df -lak | awk 'NR==1 || /disk02/'
Or
df -lak | grep -E "File|disk02"
df -lak | grep -E '(^File|disk02)'
You can shorten grep -E
to egrep
.
df -lak | grep -e File -e disk02
Just display the mount points you're interested in!
df -lak /
精彩评论