Live data from Hacker News

Unix Commands I Wish I’d Discovered Years Earlier

spin.atomicobject.com

211–220 of 259 posts

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

#211
post #131

xargs. Can't tell you how many times I wrote quickie C programs and awk scripts to do what xargs does. http://sidvind.com/wiki/Xargs_by_example

And find, that's a nice alternative to xargs when your args are a huge set of files.

Yeah, this is one of my favorite tricks as well . . .

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

#212

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…

Re: command line globbing with globstar -- is there some way to get it to cache filepaths that are frequently accessed? It's quite slow for me (I usually use aliases for that, which I was contemplating getting rid of).

Thanks a lot for wising me up to the new hotness offered by bash 4+ (zsh is also pretty slow for me for some reason, even though people keep telling me to switch to that. Maybe I'm more impatient than most folks).

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

#213
post #141
post #103

`cd -` to go back to the previous directory. Saved me LOTS of time over the past few months.

Wow. Thanks for this. I always cursed myself for forgetting to pushd, and now it turns out I didn't need to!

I recently found out that zsh lets you magically popd as well, as long as you're cding deeper into the tree. If you jump to a different subtree it will pop its internal stack until it finds a parent of the target dir.

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

#214
post #8
post #3

Never knew about the "cal" command. I especially like that you can quickly look up a previous or future month/year. >> cal 3 1973 quickly shows a calendar of March 1973

Right, you can use this to easily find the number of days in an arbitrary month in a script: % cal 2 1972 | tail +3 | wc -w 29

tail: cannot open +3 for reading: No such file or directory

What am I doing wrong?

This worked like a charm though:

cal dec 2002 | tail -6 | wc -w

(since it always takes up 6 lines, even sep 1752)

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

#215
post #8

Earlier quoted context omitted.

Right, you can use this to easily find the number of days in an arbitrary month in a script: % cal 2 1972 | tail +3 | wc -w 29

tail: cannot open +3 for reading: No such file or directory What am I doing wrong? This worked like a charm though: cal dec 2002 | tail -6 | wc -w (since it always takes up 6 lines, even sep 1752)

It might be system-dependent. I'm on OSX and the command works properly.

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

#216
For the ssh section, I'd also include sshfs. It's super handy when you want to use local (or GUI) applications for a file on a server, or just to mount your home computer as a drive while you are away. I personally use it to mount my backup server's drive on my Chromebook, effectively giving myself a 500GB hard drive whenever I need it.

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

#217

If anyone is interested there were several great posts on Hacker News a while about about useful UNIX commands [1, 2, 3]. I have also created several screencasts about command commands like the following [4], and one about the Filesystem Hierarchy Standard [5]. ls man pwd cd top ps df du cp mv rm mkdir rmdir less cat vi [1] https://news.ycombinator.com/item?id=6046682 [2] https://news.ycombinator.com/item?id=5022457…

You should do a screencast of such infinitely useful classics as tac , tsort , and sl . (Actually, I have found use for those first two on occasion. ;)

tsort is one of my favorites, mostly because it's totally pointless until you need it and then it works exactly right. I love it.

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

#218
post #53
post #18

I believe xxd is actually part of vim and not a Unix command itself. It's used to support hex-editing binary files, but you can see why it's useful in other roles as well.

The origins of xxd seem to be a bit murky, as I've seen others say the same thing about xxd being available only if vim is installed, but I've never seen a Unix system that didn't have vi(m) included. $ man xxd | grep vi Use xxd as a filter within an editor such as vim(1) to hexdump a region Use xxd as a filter within an editor such as vim(1) to recover a binary Use xxd as a filter within an editor such as vim(1) to…

Well, at least on Debian it's in `vim-common` package. http://packages.debian.org/search?searchon=contents&keywords...

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

#219
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…

Apropos 'which', let me show 'type -a':

  % type -a which
  which is a shell builtin
  which is /usr/bin/which
Convenient if you really want to know what you'll be calling.

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

#220

My biggest improvement was about finding out about .inputrc and configuring the Bash to use VIM-keybindings which is pretty handy if you are used to the editor. Also the following mapping from ESC to pressing jf via imap jf was very nice as I find it much more ergonomic. And to use it in Bash I have set editing-mode vi set keymap vi $if mode=vi set keymap vi-insert "jf": vi-movement-mode $endif set show-all-if-ambigu…

I have my Bash set to vi keybindings, but I had no idea it was possible to remap them. Now I can finally stop hitting escape in Bash too. Thank you so much!
Post reply on HN