Live data from Hacker News

Unix Commands I Wish I’d Discovered Years Earlier

spin.atomicobject.com

141–150 of 259 posts

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

#142

history | grep I use this for rsync or rdesktop when I have forgotten the long list of options & directories etc I also use ctrl R at the bash prompt but that only gives me the most recent match.

>I also use ctrl R at the bash prompt but that only gives me the most recent match. //

Are you sure, I'm using BASH on Kubuntu and I get previous matches by repeated use of ctrl+R.

Actually inspired by a previous post here I made a script "hs" that searches archived history files and shows me all past match lines. Before that I did what you do now.

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

#144
post #15

Earlier quoted context omitted.

xxd is on OSX, but not on FreeBSD. Under FreeBSD, I always use 'hd somefile.bin'.

I've been told before that `od' is the most portable, although I prefer xxd in virtually all situations.

I've known about 'od', but I've always used 'hexdump' instead. Amusingly, I just noticed that they are literally the same (hard-linked) binary on OS X 10.6, even though the arguments differ somewhat. The man pages states that 'od' is part of POSIX, which aligns with your comment about portability.

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

#145

Earlier quoted context omitted.

If you don't want to clog up your terminal, try 'less' and then hit 'F' to follow.

Better yet use 'less +F'. It's as easy to remember as tail -f. The advantage of using less here is that you can easily interrupt the tailing (ctrl-c). For example, to search. Then just hit 'F' again to restart tailing. But now your search pattern will be highlighted as the data streams by.

I'm using Ctrl+S and Ctrl+Q for interrupting tail -f, but that's missing the search feature of course.

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

#146
I recently used xxd to illustrate the concept of text encoding, and put together a little vimscript to make it easier to visualize:

  "Toggle hex edit mode
  nmap h :call ToggleHex()
  
  let g:hex_mode_on = 0
  
  function! ToggleHex()
      if g:hex_mode_on
          execute "%!xxd -r"
          let g:hex_mode_on = 0
      else
          execute "%!xxd"
          let g:hex_mode_on = 1
      endif
  endfunction
Stick this in your .vimrc, type something, use \h to convert it to hex, change a value, then \h to convert it back and observe how the text has changed. Not super useful, but a neat party trick.

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

#147

Earlier quoted context omitted.

'screen' is absolutely crucial with ssh, too.

I find tmux to be a bit more pleasant to work with. In the past it didn't do reflowing upon resize, but it does that now.

I lean towards

  nohup time whatever >whatever.out &
because so many programs behave differently when attached to a tty (like prompting for input) and I just want a plain text log that says when it succeeded or where it blew up.

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

#148
post #84
post #71

Earlier quoted context omitted.

This is a nasty hack where it is counting the output from find. What do you do when find cannot handle the sheer number of files, argument too long from the linux hardcoded MAX_ARG_PAGES We need a dedicated utility that counts inodes.

I think you are confused — at no time are any files passed as arguments in the command "find . | wc -l". Also, to count the number of files in a directory, you need to do readdir(), which will get you the names. Then, to see if any of them are directories to be recursed into you need to stat() the names individually. This is all "find" does. How , I'd very much like to know, is this "a nasty hack"?

I am not saying find is outputting files, I am saying it is decoding the full table entry for each file and formatting it, then passing that listing as an entry to wc. Which has to be a bunch of overhead that adds up when you have hundreds of thousands of files to count.

All we want from find is "count the number of inode entries in this tree branch that are type f". No formatting, no output, just count. That has to be much more efficient.

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

#149
post #79
post #48

Earlier quoted context omitted.

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 ?

Yeah, you have a cert set up and put the public cert in the identities file for each server you want to connect to. Then just SSH into each box with agent forwarding ('-a' I think, but you're best to check that). So you'll need to create an SSH cert first: ssh-keygen -b 4096 -t rsa -C "$USER created on $(hostname)" -f $USER.key Keep the private key, that's essential you keep this safe as it's literally your key to ac…

Keeping in mind that the ssh agent is root accessible on the machine in the /tmp directory looking something like this:

"ssh-ebT23030"

Meaning that anyone with root access who know the other machines that someone is accessing as well as their username can access those machines.

I've seen cases where in abnormally terminated sessions that file stays around instead of getting deleted when the session ends.

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

#150

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

I use tr all the time when I want to check $PATH:

echo $PATH | tr : '\n'

Post reply on HN