LinuxCommandLibrary
GitHubF-DroidGoogle Play Store

gc

count graph components

TLDR

Count nodes and edges in a graph (the default)
$ gc [graph.dot]
copy
Count connected components
$ gc -c [graph.dot]
copy
Count everything: nodes, edges, connected components and clusters
$ gc -a [graph.dot]
copy
Count nodes only
$ gc -n [graph.dot]
copy
Recurse into subgraphs and report counts for each
$ gc -r [graph.dot]
copy
Read a graph from standard input
$ cat [graph.dot] | gc -a
copy

SYNOPSIS

gc [-necCaDUrsv?] [files]

DESCRIPTION

gc is a graph analogue of wc: it reads one or more graphs in DOT format and prints counts of their nodes, edges, connected components and clusters to standard output. With no options it reports node and edge counts. When multiple graphs are given, a total line is printed at the end.Each input file may contain several graphs. Output is one line per graph, followed by the graph name, so results can be fed into other text tools. If no files are named, gc reads from standard input.Clusters are subgraphs whose name begins with cluster, the same convention dot uses when drawing boxed groups.

PARAMETERS

-n

Count nodes.
-e
Count edges.
-c
Count connected components.
-C
Count clusters (subgraphs whose name starts with cluster).
-a
Count all of the above; equivalent to -encC.
-r
Recurse into subgraphs, reporting counts for each.
-s
Silent: suppress output and only set the exit status.
-D
Only process directed graphs.
-U
Only process undirected graphs.
-v
Verbose output.
-?
Print usage information.

INSTALL

sudo apt install graphviz
copy
sudo dnf install graphviz
copy
sudo pacman -S graphviz
copy
sudo apk add graphviz
copy
sudo zypper install graphviz
copy
brew install graphviz
copy
nix profile install nixpkgs#graphviz
copy

CAVEATS

Input must be valid DOT format; malformed graphs cause errors rather than counts. For directed graphs, the components counted are weakly connected components. -D and -U skip graphs of the wrong kind, so a filtered run may print nothing at all.This command is unrelated to garbage collection. In PowerShell, gc is an alias for Get-Content, and some version control wrappers alias it to a commit shortcut, so check what is on your PATH before assuming.

HISTORY

gc is part of the Graphviz suite, developed at AT&T Labs Research starting in the early 1990s by Stephen North, Eleftherios Koutsofios, Emden Gansner and others. Graphviz was open-sourced in 2004 and remains actively maintained.

SEE ALSO

wc(1), acyclic(1), ccomps(1), sccmap(1), tred(1), gvpr(1), dot(1)

RESOURCES

Copied to clipboard
Kai