Non-trivial command-line fu

ls | wc -l

— -sh (@rtfmsh) February 8, 2013

Wait, what? I thought you said Non-trivial? What the hell, man?

Precisely. This tweet is an example of what this account is not about. I've grown tired of seeing very simple commands like these posted as examples of "command line magic", and I am even more tired when I see variations like these:

ls -1 | wc -l #devops #sysadmin

Here's why:

  1. Figuring out how Unix works does not count as DevOps.
  2. Don't tag everything as both "DevOps" and "SysAdmin".
    They're not the same thing... or are they? Hmmm...
  3. ls(1) defaults to printing one entry per line if output is not to a terminal -- see for yourself:
    	/* Terminal defaults to -Cq, non-terminal defaults to -1. */
    	if (isatty(STDOUT_FILENO)) {
    		if (ioctl(STDOUT_FILENO, TIOCGWINSZ, &win) == 0 &&
    		    win.ws_col > 0)
    			termwidth = win.ws_col;
    		f_column = f_nonprint = 1;
    	} else
    		f_singlecol = 1;

And so we will post more interesting commands in the future.


[Index] [next]