Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

share|improve this question
For a good read on special character (spaces, &, #, etc.) in filenames, try – 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 Jun 9 '12 at 12:05
up vote 5 down vote accepted

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/' {} +
share|improve this answer

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

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

share|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 posting your answer, you agree to the privacy policy and terms of service.

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