← Blog

UNIX Tips for the Elderly


/images/huh.png

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.

Replace Beginning & End of Line with Quotes

The best fix I've managed to come up with 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 now 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