I need to find all .nfo files in my media directory so I can use sed to change some parts. The problem is my folders have spaces in the names.

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

The output file won't found by a sed command to change the strings I want.

  • For a good read on special character (spaces, &, #, etc.) in filenames, try tuxfiles.org/linuxhelp/weirdchars.html – James Jun 9 '12 at 12:03
  • The problem is not with find, it doesn't care about special characters in file names. The problem is with what you do with the find output. Post the complete command that you tried, and explain exactly what you want to do with the files. – Gilles 'SO- stop being evil' Jun 9 '12 at 12:05

find doesn't care about special characters in file names, but the program that's parsing the output of find might. If you're using xargs, use the -print0 option to find, and the -0 option to xargs. This tells find and xargs to use null characters (which cannot appear in file names) as a separator between file names, and xargs not to do any other parsing which would mangle file names containing spaces.

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

Another way to invoke a command on many files is to use find only.

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

Type normally but put a \ after the word and before the space.

i.e. cd ~/home/New\ Volume/movies/new\ stuff

| improve this answer | |
  • I need some option to give me this : find option: media/media1/HDTV/Band\ of\ Brothers/Season\ 1/... – papampi Jun 9 '12 at 12:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.