[clug] Command of the Hour

Nathan Rickerby rickerby at gmail.com
Mon Sep 22 23:00:21 GMT 2008


On Tue, Sep 16, 2008 at 08:10:18AM +1000, Brett Worth wrote:
> One I use a lot is fmt.  If I'm editing text in vi I normally use "set wm=5" to get the
> line wrapping at the 5th to last column.  After making changes though the formatting gets
> out of whack.  I then use the "!" with a moving command to send a block of the file
> through "fmt". e.g.
> 
> 	{      -  Go to the blank line before a paragraph.
> 	!}fmt  -  Send the paragraph through fmt.

Something similar that also works quite well is par
http://www.nicemice.net/par/ it handles multiple levels of quoting
characters which is really handy for email.

One vi command I like is !!sh to execute the current line in a shell.
It's useful if you're building up a long one-liner and want to easily
document the output and your progress.  Or if you want to include the
output of previous commands in future commands, for example

ls *txt<esc>!!sh
  edit the output, insert cat at the front of the line and | grep whatever at
  the end of the line, then
<esc>!!sh

I find it easier to use than :r!

also !!dc for a calculator, for example
4534 445 * 5 / 2 + p<esc>!!dc
and again you can use the output of that in your next calculation.
It probably doesn't need need pointing out, but if you yyp before you
!!dc you can keep a copy of the input.

On Tue, Sep 16, 2008 at 11:06:11AM +1000, Jeremy Kerr wrote:
> > And sudo tee
> > Because `sudo echo foo > file` won't work when you don't have
> > permission to change file, the shell does the redirection.
> > `echo foo | sudo tee file` will work for you.
> 
> I use dd for this:
> 
> echo 1 | sudo dd of=/proc/sys/net/ipv4/ip_forward
> 
> - which gives you the same semantics as bash redirection (ie, the output 
> isn't copied to stdout)

As much as I appreciate that use of dd, tee has the advantage that you
can use the -a option to append to the file like >>.


More information about the linux mailing list