Mar 06, 2008

  • Category: Misc
  • comment(s)

Recent Posts

Categories

Archives

UNIX Tips For The Elderly

I often want to do something to a bunch of files on the filesystem.

E.g.

find Music/ | xargs -J % echo 'Do something to ' %

The problem is that sometimes the filenames have spaces in them which will cause:

find Music/ | xargs -J % 'Do something to ' %
xargs: unterminated quote

Useless. The best fix I’ve managed to come up with which I couldn’t recall hence the blog post, is to replace the beginning and end of the line with quotes to make the shell happy, e.g.

find Music/ | sed -e 's/^/"/' -e 's/$/"/'
"Music//iTunes/iTunes Music/Yael Naïm/Yael Naïm/03 New Soul.m4a"

So I can do things like:

find Music/ | sed 's/^/"/' | sed 's/$/"/' | xargs -J % ls -d %
Music//iTunes/iTunes Music/Yael Naïm/Yael Naïm/03 New Soul.m4a

or

find Music/ | sed 's/^/"/' | sed 's/$/"/' | xargs -J % file %
Music//iTunes/iTunes Music/Yael Naïm/Yael Naïm/03 New Soul.m4a: ISO Media, MPEG v4 system, iTunes AAC-LC

Comments

comments powered by Disqus