Make xargs handle filenames that contain spaces

前端 未结 12 1188
北恋
北恋 2020-11-29 15:21
$ ls *mp3 | xargs mplayer  

Playing Lemon.  
File not found: \'Lemon\'  
Playing Tree.mp3.  
File not found: \'Tree.mp3\'  

Exiting... (End of file)  
12条回答
  •  余生分开走
    2020-11-29 15:45

    xargs on MacOS doesn't have -d option, so this solution uses -0 instead.

    Get ls to output one file per line, then translate newlines into nulls and tell xargs to use nulls as the delimiter:

    ls -1 *mp3 | tr "\n" "\0" | xargs -0 mplayer

提交回复
热议问题