Live data from Hacker News

Unix Commands I Wish I’d Discovered Years Earlier

spin.atomicobject.com

131–140 of 259 posts

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

#134
post #15
post #9

I'm unreasonably excited about discovering xxd.

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.

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

#135
post #119

Rather than 'man 7 ascii', there's the 'ascii' command itself. It will also provide encodings for single characters: $ ascii a ASCII 6/1 is decimal 097, hex 61, octal 141, bits 01100001: prints as `a' Official name: Miniscule a Other names: Small a, Lowercase a ASCII 0/10 is decimal 010, hex 0a, octal 012, bits 00001010: called ^J, LF, NL Official name: Line Feed Other names: Newline, \n

Which Unix includes that command?

Debian GNU/Linux. It's the 'ascii' package.

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

#136
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.

Yeah, before I was heavily into automation (i.e. puppet) this was my go to command. Use a for loop and ssh to run things on a group of systems. for host in h-abc h-def h-ghi h-jkl h-mno h-pqr h-stu h-vwx h-yza; do ssh -l root $host "hostname; echo "1.1.1.1 server" >> /etc/hosts"; done This would iterate over hosts (h-abc .. h-yza) and run the commands "hostname; echo "1.1.1.1 server" >> /etc/hosts". Or maybe use a fo…

dsh (distributed/dancer's shell) is a wrapper around ssh which provides that capability. Plus you can define hostlists.

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

#137

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.

Actually, after hitting C-R , you can keep pressing C-R to search backwards through the history. Or C-S to search forwards. More info: (bash uses emacs editing mode by default) http://www.gnu.org/software/emacs/manual/html_node/emacs/Bas...

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

#138
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).

It appears that on OS X 10.6 cal is from 2004, and on Ubuntu it's a 2009 build. The 2009 build highlights the day of the month.

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

#140

Command line globbing! For the uninitiated: Let's say my pwd is `/home/projects` and i want to edit `/home/projects/a_huge_sprawling_app/940j_394/lol/flight_controller.rb` `vim **/flight_controller.rb` opens our flight_controller.rb straight away. In terms of effort, this allows you to basically omit a `find -name` when you're in a rush to edit some damn file where the hell is it again damn we need to reevaluate this…

FWIW, the double-star recursive globbing was added in Bash 4.0. My reading of the manual[1] suggests it is disabled by default, and can be enabled by setting the 'globstar' shell option. I believe it's enabled by default in zsh.

[1]: https://www.gnu.org/software/bash/manual/bash.html#The-Shopt...

Post reply on HN