Live data from Hacker News

Unix Commands I Wish I’d Discovered Years Earlier

spin.atomicobject.com

41–50 of 259 posts

Re: Unix Commands I Wish I’d Discovered Years Earlier

#41
There are some other useful commands for organizing the stream of datas for pretty printing:

column - columnify the incoming stream into columns

pr - set up incoming stream for pretty printing including columnification along or across the screen

tr - sanitize input, collapse several delimiters into one

Re: Unix Commands I Wish I’d Discovered Years Earlier

#46
post #35
post #33

Earlier quoted context omitted.

I have xxd on my FreeBSD setup. uname -rms FreeBSD 9.1-RELEASE-p19 amd64 Although the xxd man page doesn't have the BSD label, and is from 1996, so I'm not sure if xxd only recently found its way into FBSD. This manual page documents xxd version 1.7 AUTHOR (c) 1990-1997 by Juergen Weigert

It maybe in ports, but it's not part of the base install: $ xxd xxd: Command not found. $ uname -rms FreeBSD 9.1-RELEASE amd64 edit: fixed typo where I put xdd instead of xxd

s/xdd/xxd/g

Re: Unix Commands I Wish I’d Discovered Years Earlier

#47
post #39

I know it's not exactly an unknown command, but I didn't know about "sort" until last week. It's freaking fast and convenient, sorts hadoop reduce results like a champ.

One of my favorite things about unix is that you can chain commands together with pipe (|). Say for example that you have a example data file that looks like this:

  # Deflection    Col-Force       Beam-Force 
  0.000              0              0    
  0.001            104             51
  0.002            202            101
  0.003            298            148
  0.0031           104            149
  0.004            289            201
  0.0041           291            209
  0.005            104            250
  0.010            311            260
  0.020            104            240
  
You can chain commands together to quickly get ball park figures. I do this all the time when reviewing log data to get simple counts and look for anomalies.

  $ cat data.txt | grep -v '#' | awk '{print $2}' | sort | uniq -c
      1 0
      4 104
      1 202
      1 289
      1 291
      1 298
      1 311
Let me break this down a little. I cat data.txt, which just prints the contents to the console, I use grep to remove the # header, then use awk to print the second data column, the sort the values for my next procedure, and lastly I use uniq -c, which takes the input and counts all the unique values. So you can see that "4 104" means that 4 instances of 104 were found. I use this often to look at httpd logs for IP addresses or to review sudo commands, etc. Very handy!

ps. there are optimizations that could be done here, but that what is great about unix and "one function" utilities. There are many ways to the same destination!

Re: Unix Commands I Wish I’d Discovered Years Earlier

#48
post #28

One of the more useful bits of ssh is not mentioned: remotely running commands. Example: ssh username@host "echo $HOSTNAME && sudo somecommand && cat somecommand.log" There's probably a better way to do this, but in a pinch I can fix a problem on dozens of machines just by altering the host string.

Still about ssh :

"typing a password on your local machine once, then using a secure identity to login to several remote machines without having to retype your password by using an ssh key agent. This is awesome. "

Sounds awesome, but I really didn't understand what he means. Is he talking about using a certificate (-i option) to log in ?

Re: Unix Commands I Wish I’d Discovered Years Earlier

#50
post #35

Earlier quoted context omitted.

It maybe in ports, but it's not part of the base install: $ xxd xxd: Command not found. $ uname -rms FreeBSD 9.1-RELEASE amd64 edit: fixed typo where I put xdd instead of xxd

s/xdd/xxd/g

Sorry, that was a typo when posting on here. I did originally run it as xxd:

    root@primus:/usr/ports # xxd
    xxd: Command not found.
edit:

It doesn't show up in my ports either:

    root@primus:/usr/ports # make search name=xxd
    Port:   textproc/xxdiff
    Moved:
    Date:   2013-07-26
    Reason: Has expired: Depends on Qt 3.x

    Port:   textproc/xxdiff-scripts
    Moved:
    Date:   2013-07-26
    Reason: Has expired: Depends on Qt 3.x
Obviously xxdiff is a different (if you pardon the pun) utility, but xxd should show up in that list also.

edit 2:

Another comment on here might explain why you're seeing xxd and I'm not: https://news.ycombinator.com/item?id=6360814 (it's not a separate utility, it's part of vim)

Since I didn't install vim on that box (just use basic vi), xxd wouldn't have installed as part of it. Where as in a jail on the same box, xxd does exist:

    root@primus:/usr/ports # which vim xxd
    vim: Command not found.
    xxd: Command not found.
    
    root@primus:/usr/ports # jexec 1 which vim xxd
    /usr/local/bin/vim
    /usr/local/bin/xxd
Post reply on HN