当目录名中有空格时如何使用find?

我需要在我的媒体目录中找到所有.nfo文件,以便我可以使用sed来更改某些部分。 问题是我的文件夹名称中有空格。

 find /media/media1/HDTV -name \*.nfo -type f media/media1/HDTV/Band of Brothers/Season 1/ … 

sed命令找不到输出文件来更改我想要的字符串。

find不关心文件名中的特殊字符,但是解析find输出的程序可能。 如果您正在使用xargs ,请使用-print0选项find ,并使用xargs-0选项。 这告诉findxargs使用空字符(不能出现在文件名中)作为文件名之间的分隔符,而xargs不做任何其他解析会破坏包含空格的文件名。

 find /media/media1/HDTV -name '*.nfo' -type f -print0 | xargs -0 sed -i 's/pattern/replacement/' 

在许多文件上调用命令的另一种方法是使用find

 find /media/media1/HDTV -name '*.nfo' -type f -exec sed -i 's/pattern/replacement/' {} + 

正常输入,但在空格后面放一个\。

cd ~/home/New\ Volume/movies/new\ stuff