News for hackers. Stuff that matters.
Re:Top Ten One-Liners from CommandLineFu Explained by colonhyphenp on Thursday March 18, 2010 @09:08AM (#1201149)
Last year a friend taught me about the bash trick "CTRL-R" <start typing 'ssh' or some other previously run command> on the command line for reverse history searching, and it is an amazing time saver. It acts as a great alternative to #8, "Find the last command that begins with “whatever,” but avoid running it"

$ !whatever:p

Re:Top Ten One-Liners from CommandLineFu Explained by 10ren on Thursday March 18, 2010 @01:09PM (#1201825)
I use up-arrow for that. My .inputrc has:

    "\e[A": history-search-backward
If you don't type anything, it acts exactly as the old up-arrow.
Re:Top Ten One-Liners from CommandLineFu Explained by imurray on Friday March 19, 2010 @09:34AM (#1204074)
Or in ~/.zshrc:

    bindkey '\e[A'  history-beginning-search-backward
Re:Top Ten One-Liners from CommandLineFu Explained by oyving on Thursday March 18, 2010 @09:24AM (#1201188)
An important addition to that is to repeatedly hit ctrl-r to cycle through the matching commands in the history.
Re:Top Ten One-Liners from CommandLineFu Explained by erlanger on Thursday March 18, 2010 @09:40AM (#1201239)
How do you reverse the search? <S-C-R> didn't do it for me. Either way this could be a good substitute for what I do now, tediously grepping .zsh/bash_history...
Re:Top Ten One-Liners from CommandLineFu Explained by mziulu on Thursday March 18, 2010 @11:40AM (#1201557)
If by reverse you mean going forward instead of backwards, that should be done with Ctrl-S; it does not work in Bash though, since Ctrl-S locks the scrolling of the terminal. I believe this behavior can be overridden, through some .xinputrc settings perhaps, but I haven't still found enough motivation to look it up!

edit: ok, I've found this: http://wiki.archlinux.org/index.php/Bash#History_search

Re:Top Ten One-Liners from CommandLineFu Explained by araneae on Thursday March 18, 2010 @01:19PM (#1201860)
I'm pretty I learned this from reading an article on HN... anyone got a citation for me?
Re:Top Ten One-Liners from CommandLineFu Explained by pkrumins on Thursday March 18, 2010 @06:31PM (#1202711)
Perhaps my article "The Definitive Guide to Bash History?"

http://www.catonmat.net/blog/the-definitive-guide-to-bash-co...

Re:Top Ten One-Liners from CommandLineFu Explained by duck on Thursday March 18, 2010 @07:59AM (#1201032)
#3. Save a file you edited in vim without the needed permissions

:w !sudo tee %

I've used vim for a long time, but didn't know about this one.

Re:Top Ten One-Liners from CommandLineFu Explained by erlanger on Thursday March 18, 2010 @09:41AM (#1201244)
Of course it assumes sudo's present.
Re:Top Ten One-Liners from CommandLineFu Explained by sketerpot on Thursday March 18, 2010 @02:53PM (#1202141)
When I need to do number one -- add sudo to the previous command -- I just use the up arrow, Ctrl-a to get to the beginning of the line, and add sudo. It's a little slower than the method in the article, but I find it downright dangerous to have something in your command history that means "do whatever was typed previously as root".
Re:Top Ten One-Liners from CommandLineFu Explained by chronomex on Thursday March 18, 2010 @03:54PM (#1202326)
It actually won't be in your command history as that. The entry will go into your command history as "sudo previous-line".Try it yourself:

  $ true
  $ echo !!
  echo true
  true
  [up-arrow to see]
  $ echo true
Re:Top Ten One-Liners from CommandLineFu Explained by sketerpot on Thursday March 18, 2010 @11:32PM (#1203313)
Nice! Consider my objection withdrawn, and my compliments to the developers of bash.
Re:Top Ten One-Liners from CommandLineFu Explained by vorador on Friday March 19, 2010 @09:27AM (#1204061)
I think in this case, the compliments should go to bill joy, the creator of csh.
Re:Top Ten One-Liners from CommandLineFu Explained by pvg on Thursday March 18, 2010 @08:05AM (#1201044)
Couple of little nits - 5. and 8. are not bash specific and neither are event designators, these work fine in tcsh and zsh. I think caret substitution might have actually come from the *csh world. Not that big of a deal since bash is so prevalent these days but hey, a pedantipoint is a pedantipoint.
Re:Top Ten One-Liners from CommandLineFu Explained by pkrumins on Thursday March 18, 2010 @08:12AM (#1201055)
Good points, I like being corrected where appropriate.
Re:Top Ten One-Liners from CommandLineFu Explained by 10ren on Thursday March 18, 2010 @01:15PM (#1201842)
I'm always finding new places to use brace expansion. Recently I've starting doing

    diff longpath_andor_longfilename{a,b}*
Re:Top Ten One-Liners from CommandLineFu Explained by aw3c2 on Thursday March 18, 2010 @07:16AM (#1200977)
On #10. Capture video of a linux desktop you suggest removing -r and using -b 250kbit/s. Did you try that? ;)

Is there a way to use a better codec?

Re:Top Ten One-Liners from CommandLineFu Explained by pkrumins on Thursday March 18, 2010 @07:24AM (#1200986)
Didn't try it. It actually turns out you need -r. Seems like an exception. I updated the article to reflect that. :)

The output codec? Use `-vcodec <format>`, where <format> is a video coded output by `ffmpeg -formats`.

Update: The whole comment about kbit/s was actually unnecessary, so I edited the article and replaced it with a better comment.

Re:Top Ten One-Liners from CommandLineFu Explained by aw3c2 on Friday March 19, 2010 @03:55AM (#1203633)
I should have mentioned the message in my comment, sorry about the wittyness. Thanks for updating!
Re:Top Ten One-Liners from CommandLineFu Explained by sown on Friday March 19, 2010 @06:19AM (#1203808)
My favorite is the modifier for histories.

$ ls a b c

a b c

$ ls !$

ls c

c

$ ls a b c

a b c

$ ls !:3 !:2 !:1 !:0

ls c b a ls

ls: ls: No such file or directory

a b c

$

Re:Top Ten One-Liners from CommandLineFu Explained by eplanit on Thursday March 18, 2010 @12:23PM (#1201690)
Very helpful, thanks. To my tech. note list it goes!
Re:Top Ten One-Liners from CommandLineFu Explained by bho on Thursday March 18, 2010 @01:29PM (#1201895)
neat. thanks for the explanations!