Live data from Hacker News

Moreutils – Unix tools that nobody thought to write (2012)

joeyh.name

11–20 of 225 posts

Re: Moreutils – Unix tools that nobody thought to write (2012)

#13
post #6
post #5

Earlier quoted context omitted.

> Why not use > file? I'm assuming sponge buffers everything in memory so you don't get concurrent modification bugs.

Yes, if you try to sed a file back to itself for instance you'll get a truncated file (or maybe a no-op?). In fact, that's exactly the example sponge's manpage uses.

That redirection will make the shell truncate the file long before sed has a chance to open it.

Re: Moreutils – Unix tools that nobody thought to write (2012)

#14
post #6
post #5

Earlier quoted context omitted.

> Why not use > file? I'm assuming sponge buffers everything in memory so you don't get concurrent modification bugs.

Yes, if you try to sed a file back to itself for instance you'll get a truncated file (or maybe a no-op?). In fact, that's exactly the example sponge's manpage uses.

It's a truncated file:

  $ cat test
  moo
  $ cat  test
  $ cat test
  $

Re: Moreutils – Unix tools that nobody thought to write (2012)

#15
Nice collection of quite useful tools. Some of these can be easily replicated by using a more modern shell (bash, zsh) like mispipe, others are just shortcuts (e.g. ifne, chronic).

But what immediately stood out to me is `vidir`. I really like the idea of editing file names with an editor. Using loops and regex in a shell for mass renaming can be a mess. It should be way easier with `vim`. This tool made me install moreutils.

Re: Moreutils – Unix tools that nobody thought to write (2012)

#16

I wrote a util a bit like this when I realised there was no command for emptying a directory: https://github.com/adamserafini/emptydir

What the difference in just deleting the whole directory and recreating it with `mkdir`. Or just do an `rm -rf dir/*`?

Re: Moreutils – Unix tools that nobody thought to write (2012)

#18
post #16

I wrote a util a bit like this when I realised there was no command for emptying a directory: https://github.com/adamserafini/emptydir

What the difference in just deleting the whole directory and recreating it with `mkdir`. Or just do an `rm -rf dir/*`?

Hidden directories, links within dir... (usually, you want a "nofollow" default for destructive operations)

Re: Moreutils – Unix tools that nobody thought to write (2012)

#19
post #6

Earlier quoted context omitted.

Yes, if you try to sed a file back to itself for instance you'll get a truncated file (or maybe a no-op?). In fact, that's exactly the example sponge's manpage uses.

It's a truncated file: $ cat test moo $ cat test $ cat test $

I was wondering about tee for that:

  $ cat test 
  moo
  $ cat  /dev/null
  $ cat test
  moo
...seems to work. Am I just getting lucky with a race condition?
Post reply on HN