Live data from Hacker News

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

joeyh.name

21–30 of 225 posts

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

#21

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

While your code is very nicely factored, well-documented and quite readable, bash is not an easy language for this sort of utility. Any names containing spaces or starting with dashes require very careful handling.

If you do stick with bash, I would recommend giving shellcheck a try. It won't catch everything, but I've learned a lot from running it on my code.

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

#22
post #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 m…

Check out renameutils[1], which has the advantage over vidir of doing sanity checks before renaming.

Also, this can be done in emacs using wdired.

[1] - http://www.nongnu.org/renameutils/

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

#23
With the annoying half-way implementation of GNU parallel. Does not support the basic features, is not better nor faster, but still tramples over this namespace.

I really like many of the moreutils tools, but dealing with constant parallel breakage (kind of a Hadoop for dummies) is annoying.

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

#24
post #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 m…

Check out renameutils[1], which has the advantage over vidir of doing sanity checks before renaming. Also, this can be done in emacs using wdired. [1] - http://www.nongnu.org/renameutils/

The ranger file manager also has this built in.

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

#25
post #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 m…

See writable dired-mode in emacs. Here's a short demo: https://youtu.be/8l4YVttibiI

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

#26
post #19

Earlier quoted context omitted.

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?

Possible, since you don’t pipe into the file but instead ask tee to write into it.

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

#27
post #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 m…

On most POSIX systems you can use fc(1) to edit a command in your $EDITOR. In vi(1) and friends you can then use "%!ls" to replace the contents of the buffer with directory listing and edit the commands you want.

https://pubs.opengroup.org/onlinepubs/9699919799/utilities/f...

https://pubs.opengroup.org/onlinepubs/9699919799/utilities/v...

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

#28
post #19

Earlier quoted context omitted.

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?

Yes, check this, with f.txt containing 99999 numbers:

    $ seq 1 99999 > f.txt
    $ cat  /dev/null
    $ wc -l f.txt
    23696 f.tx

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

#29
post #19

Earlier quoted context omitted.

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?

> Am I just getting lucky with a race condition?

Probably this is buffering, either from dd or from the kernel.

  $ dd if=/dev/urandom bs=1M count=1 of=test.bin 2>/dev/null
  $ cp test.bin test2.bin
  $ cat /dev/null
  $ diff test.bin test2.bin
  Binary files test.bin and test2.bin differ
  $ wc -c test{2,}.bin
   131072 test2.bin
  1048576 test.bin
Notice the file got truncated at exactly 128k; a nice round size for a write cache.

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

#30
post #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 m…

It's one of the reasons I like using the nnn file manager. It has a batch rename feature with exactly that functionality.
Post reply on HN