how to identify on command line terminal emulator apps and packages that have active network connections
If you mean by network connection the applications that has &quot;android.permission.INTERNET&quot; permission, then run this shell script:

for package in $(pm list packages -3 | cut -f2 -d&quot;:&quot;); do
dumpsys package $package | grep &quot;android.permission.INTERNET: granted=true&quot; &gt; /dev/null &amp;&amp; echo $package
done;


If you want to list all applications that are connected to internet:

netstat -tuplna

That will list all application that has an established connection

If you want for each App an their mobile data usage:

for package in $(pm list packages | cut -f2 -d&quot;:&quot;); do echo $package; pm dump $package | grep  &quot;Mobile network&quot;; done;


To kill an App:

am force-stop PACKAGE_NAME


Clear cache:

pm clear PACKAGE_NAME