top | item 1200900

Top Ten One-Liners from CommandLineFu Explained

172 points| pkrumins | 16 years ago |catonmat.net | reply

23 comments

order
[+] colonhyphenp|16 years ago|reply
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

[+] 10ren|16 years ago|reply
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.
[+] oyving|16 years ago|reply
An important addition to that is to repeatedly hit ctrl-r to cycle through the matching commands in the history.
[+] araneae|16 years ago|reply
I'm pretty I learned this from reading an article on HN... anyone got a citation for me?
[+] duck|16 years ago|reply
#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.

[+] erlanger|16 years ago|reply
Of course it assumes sudo's present.
[+] sketerpot|16 years ago|reply
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".
[+] chronomex|16 years ago|reply
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
[+] pvg|16 years ago|reply
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.
[+] pkrumins|16 years ago|reply
Good points, I like being corrected where appropriate.
[+] 10ren|16 years ago|reply
I'm always finding new places to use brace expansion. Recently I've starting doing

    diff longpath_andor_longfilename{a,b}*
[+] aw3c2|16 years ago|reply
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?

[+] pkrumins|16 years ago|reply
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.

[+] sown|16 years ago|reply
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

$

[+] eplanit|16 years ago|reply
Very helpful, thanks. To my tech. note list it goes!
[+] bho|16 years ago|reply
neat. thanks for the explanations!