News for hackers. Stuff that matters.
Re:Programs that have saved me 100+ hours by vram22 on Thursday March 16, 2017 @03:13PM (#13888118)
In bash:

$_ in a command gets substituted by the last argument of the last command you typed - happens to be useful surprisingly often. Simple example: copy a file to some other directory, then cd or pushd to that directory:

$ cp some_file /long/path/to/directory

# cd $_

But there are many other cases where I regularly find it useful.

_ also evaluates to result of the last expression in the Python interactive shell, and probably in IPython (command-line version) as well - need to confirm it about IPython.

Edited for formatting of commands above.

Re:Programs that have saved me 100+ hours by ryandrake on Thursday March 16, 2017 @03:50PM (#13888537)
Another useful bash thing: !! (which substitutes the last command you entered)

cat /really/long/path/to/something/only/readable/by/root

cat: Permission denied (goddamnit)

sudo !!

Re:Programs that have saved me 100+ hours by blacksmith_tb on Thursday March 16, 2017 @07:08PM (#13889967)
Oh yeah, I sudo bang-bang all the time (it's in other shells, too, zsh for example). I am also fond of !$, which is the object of your last command - lots of times I will ls a file to see the timestamp or confirm it's there; and then want to open it / edit it / rm it, which just looks like

$ ls /long/path/to/file.ext

$ less !$

Re:Programs that have saved me 100+ hours by waterhouse on Thursday March 16, 2017 @07:30PM (#13890093)
What if you need to run a third version of the command, or a version that involves deletions, e.g. "less /really/long/path/to/..."?

  bash-3.2$ less /var/log/authd.log.0.gz 
  "/var/log/authd.log.0.gz" may be a binary file.  See it anyway? 
  bash-3.2$ 
I type: control-P control-A meta-D zcat control-E | SPACE less

  bash-3.2$ zcat /var/log/authd.log.0.gz | less
On the OS X terminal, you have to configure it to treat option as meta before the meta-D above will work. I forget whether common Linux terminals require such configuration. (Edit: zless would work just as well here, and on Linux "less" appears to basically have the functionality of zless.)
Re:Programs that have saved me 100+ hours by mwpmaybe on Friday March 17, 2017 @02:25AM (#13891972)
With set -o vi:

    <ESC> k cw zcat <ESC> A <SPACE> | <SPACE> less <CR>
Very natural for any Vi user: go up a "line", change the first word, then append.
Re:Programs that have saved me 100+ hours by vram22 on Thursday March 16, 2017 @04:30PM (#13888887)
Yes, that's a good one :)

There are zillions more such that can be done in Unix, of course, if one puts one's mind to it and experiments, even without spending a lot of time. Another simple one I use some is to define some environment variables to the value of long directory names to which I need to go often as part of some project. Then I can just do:

cd $short_name_for_that_dir

A shell alias can also be used instead.

Re:Programs that have saved me 100+ hours by deathanatos on Thursday March 16, 2017 @10:11PM (#13890818)
Another one I love is that both bash & zsh can edit the current command in $EDITOR. In bash, it's ^X^E by default, and in zsh, I think you have to bind it. (it's edit-command-line, which I strangely can't find in man zshzle.)
Re:Programs that have saved me 100+ hours by tyrylu on Thursday March 16, 2017 @03:26PM (#13888283)
Not the original poster, but the _ trick works in ipython as well.
Re:Programs that have saved me 100+ hours by vram22 on Thursday March 16, 2017 @03:39PM (#13888423)
Cool, thanks for confirming.
Re:Programs that have saved me 100+ hours by billbrown on Thursday March 16, 2017 @07:01PM (#13889941)
Instead of $_ you may find ESC+. easier. I have.
Re:Programs that have saved me 100+ hours by vram22 on Friday March 17, 2017 @08:29AM (#13893420)
Cool, didn't know of that one.