Two command-line scripts to help with the small-width screen on the Nanonote.

Delbert Franz ddf at
Wed Oct 10 19:57:57 EDT 2012

One challenge with the Ben Nanonote is the narrow width of the screen.  
Many command-line applications assume that there is at least an 
80-character width.  Consequently, many output lines wrap around.  So 
here are two modified commands to help improve that outcome.  

I like to use "ls -l" a lot.  However, on the Nanonote, the user and 
group are always "root", so much of the output gives no useful 
information.  One can use the really tiny unfuzzy fonts and get 
80-characters across the screen.  However, color is not supported and 
one gets small variations in "whiteness" of the characters.  To get 
color text one must revert to one of the small fuzzy fonts and then 
the "ls -l" lines wrap around.  

The following script uses gawk in a pipeline to reformat the output 
from "ls -l".  One addition I would like to make but have not found a 
way to do it cleanly, is to add color to the various links.  So the 
color for the file pointed to by a link is set as that for an 
executable file, which is often correct, but not always.  

ls -l | gawk '{ if (substr($1,1,1) == "l"){
   printf("%10s %8s %s%s%s %s %s%s%s \n",$1,$5, "\033[1;36m",$9, "\033[0m", $10, "\033[1;32m", $11,"\033[0m ")
 else if (substr($1,1,1) == "d")
   printf("%10s %8s %s%s%s \n", $1, $5, "\033[1;34m", $9, "\033[0m ")
 else if (substr($1,1,1) == "c")
   printf("%10s %8s %s%s%s \n", $1, $5, "\033[1;35m", $10, "\033[0m ")
 else if (substr($1,4,1) == "x")
   printf("%10s %8s %s%s%s \n", $1, $5, "\033[1;32m", $9, "\033[0m ")
   printf("%10s %8s %s \n", $1, $5, $9)

I'm also not sure that all the "types" of items have been defined.  
However, it works well enough for me and it fits within the screen 
width with space to spare.  

I have also found the "vmstat" command interesting to use to monitor 
swap, ram usage, and cpu usage.  Again a number of columns of data 
from this command prove to be zero all the time or are not of interest 
to me.  See the man page for vmstat to sort out the flags I used:-) 

I call the script "mstat" and it has one command-line argument that 
gives the seconds between output of the statistics.  It will run until 
it is killed with a CNTRL-C key combo.  

vmstat -an $1 | gawk '{ if ($1 == "procs")
   printf(" -----------memory----------  ----cpu----\n" )
 else if ($1 == "r")
   printf("   swpd   free  inact active  us sy id wa\n")
   printf("%7d%7d%7d%7d %3d%3d%3d%3d\n", $3, $4, $5, $6, $13, $14, $15, $16)

Understanding memory usage for Linux is a bit of a challenge and this 
script helps a bit.  It also appears to have small overhead.


More information about the discussion mailing list