0

I am using wc -l to count the number of lines I get as output from docker ps command. Sometimes there are no containers in the list and it just gives empty line but wc -l counts that as well and says the answer as 1. How can I avoid this

ambikanair
  • 4,004
  • 11
  • 43
  • 83

2 Answers2

1

try the count option of grep and dot means any character which is not blank.

docker ps|grep -c .
P....
  • 17,421
  • 2
  • 32
  • 52
0

Use instead a better-for-programs docker ps output -q. It only displays containers ids

docker ps -q | wc -l
Robert
  • 33,429
  • 8
  • 90
  • 94