Live data from Hacker News

Unix Commands I Wish I’d Discovered Years Earlier

spin.atomicobject.com

91–100 of 259 posts

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

#91

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 have been using both "tail -f" and less for years, and never knew about this. Thank you. In three lines of text, you have made my logfile-centric life oh-so-much easier to deal with.

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

#92
post #80

Replaces the current day of the month with []: $ cal | sed "s/.*/ & /;s/ $(date +%e) / [] /" September 2013 Su Mo Tu We Th Fr Sa 1 2 3 4 5 6 7 8 9 [] 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30

Hmm, the day is already highlighted for me (inverted color).

You can turn that off with:

  cal | cat

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

#93
post #58

Earlier quoted context omitted.

The single most useful thing about ssh to me is that it connects stdout/in across the channel (this is behavior inherited from rsh). This allows for e.g.: % (cd /foo; tar cpf - .) | ssh bar \(cd /baz\; tar xpf -\) Or: % cat ~/.ssh/id_rsa.pub | ssh bar tee -a .ssh/authorized_keys

Forgive my ignorance, but I don't know what what it means to connect "across the channel", but it sounds important. Do you know a link that explains the concept? I've failed to Google it.

He's talking about forwarding stdin and stdout across the SSH connection to the program that SSH is running on the other end; such that the stdin of ssh is passed unmodified to the program and vice-versa.

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

#94

Earlier quoted context omitted.

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 t…

Yes, there are some ways to simplify. You can get rid of the "UUOC". Instead of cat data.txt | grep -v '#' you can do: grep -v '#' data.txt or you can simplify further by moving the grepping into awk, so that the full command becomes awk '!/#/{print $2}' data.txt | sort -n | uniq -c sort -n is good to use for sorting numbers. You could probably pull the sort | uniq -c into awk somehow, but I have already demonstrated…

You can also pre-sort if you have GNU utils:

    sort -n -f 2 

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

#95
post #20

I recently discovered whatis and I love it.

Yup, it's a great way to review a lot of commands without reading every man page.

Want to find all the tools on your system that use the curses library (for user-friendly interfaces)? Try this:

  for i in `\ls /bin/* /sbin/* /usr/bin/* /usr/sbin/* | sort -u` ; do ldd $i 2>/dev/null | grep -q curses && whatis `basename $i` ; done | grep -v 'nothing appropriate'
Don't know how your current path finds a program? Use which:

  pwillis@zippy:~$ which df
  /usr/bin/df
  pwillis@zippy:~$ which mount
  /bin/mount
Annoyed that /sbin and /usr/sbin aren't in your path? Use whereis:

  pwillis@zippy:~$ which ifconfig
  which: no ifconfig in (/usr/local/bin:/usr/bin:/bin:/usr/games:/usr/lib64/kde4/libexec:/usr/kerberos/bin:/usr/lib64/java/bin:/usr/lib64/java/jre/bin:/usr/lib64/qt/bin:/usr/share/texmf/bin:.)
  pwillis@zippy:~$ whereis ifconfig
  ifconfig: /sbin/ifconfig /usr/man/man8/ifconfig.8.gz /usr/share/man/man8/ifconfig.8.gz /usr/X11/man/man8/ifconfig.8.gz

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

#97
post #58
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.

The single most useful thing about ssh to me is that it connects stdout/in across the channel (this is behavior inherited from rsh). This allows for e.g.: % (cd /foo; tar cpf - .) | ssh bar \(cd /baz\; tar xpf -\) Or: % cat ~/.ssh/id_rsa.pub | ssh bar tee -a .ssh/authorized_keys

This is a bit of a pet peeve of mine, but cd/tar should likely be joined with && - in other words, in what directory do you want tar to (not) run if cd fails? So consider:

    % (cd /foo && tar cpf - .) | ssh bar '(cd /baz && tar xpf -)'
or explore something like:

    % rsync -aSHx --update --delete -e ssh /foo/ user@bar:baz/.

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

#99
post #65
post #63

Earlier quoted context omitted.

I didn't add xxd on my local FBSD (installed last night) setup, and my remote FBSD shell has xxd installed by default... $ uname -rms FreeBSD 9.1-RELEASE-p7 amd64 $ xxd -v xxd V1.10 27oct98 by Juergen Weigert Perhaps different builds have different things included?

No, it installs as part of vim : https://news.ycombinator.com/item?id=6361210

http://vim.wikia.com/wiki/Improved_hex_editing

You're right, xxd is included with vim, but as an external program.

Vim provides this capability through the external program xxd, which is included by default in standard distributions of Vim.

My pedantic nature was hung up on the release dates of the respective programs, as xxd predates vim on Unix.

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

#100

I really love pushd/popd.

For OpenBSD ksh I've got this hack

  alias d='[ ${#DIRSTACK[@]} -gt 0 ] && for i in `jot ${#DIRSTACK[@]} 1 ${#DIRSTACK[@]} 1`; do echo ${DIRSTACK[$i-1]}; done; echo $PWD'
  alias popd='[ ${#DIRSTACK[@]} -gt 0 ] && { cd "${DIRSTACK[${#DIRSTACK[@]}-1]}"; unset DIRSTACK[${#DIRSTACK[@]}-1]; }; d'
  alias pushd='DIRSTACK[${#DIRSTACK[@]}]="$PWD"; cd'
Post reply on HN