Super User is a question and answer site for computer enthusiasts and power users. 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 search for places.sqlite on a system which may have spaces in the folder name; This works without spaces in folder name:

    for each in `find /home/ -name "places.sqlite" | grep -i ".mozilla/firefox"` ;do
         echo "${each}"

Which prints: /home/itsupport/.mozilla/firefox/d2gigsya.default/places.sqlite (for example)

However, if the folder contains spaces it chops up path to the file and breaks my script!

To recap, this type of folder WOULD work in the script:

    $ sudo find /home/ -name "places.sqlite" | grep -i ".mozilla/firefox"

And this folder with spaces does NOT work in the script:

    $ sudo find /home/ -name "places.sqlite" | grep -i ".mozilla/firefox"
    /home/itsupport/.mozilla/firefox/Random Ass Location/places.sqlite

I know that you can use $(command) or something but I'm not sure what to do when I'm using the find as the loop variable. Maybe that is my mistake here. Anyway, any help would be great.

share|improve this question

migrated from Jan 11 '13 at 3:12

This question came from our site for professional and enthusiast programmers.

up vote 3 down vote accepted

find has the -print0 flag to deal with this problem:


find . -print0 | while read -d $'\0' file
    echo ${file}


$ ls  space name
$ ./ 
./space name
share|improve this answer
Thanks! This worked for me : find /${1}/ -name "${2}" -print0 | while read -d $'\0' file ;do – Mike Q Jan 11 '13 at 0:03
however the extra grep I had in there didn't work. Figuring that part out now. – Mike Q Jan 11 '13 at 0:04

Another option is to use IFS to split on line end, instead of any whitespace characters.

for bla in ....
IFS="$oldIFS" # restoring to avoid surprising the rest of the script
share|improve this answer

Since the files are in well-known locations, you can just use

for each in /home/*/.mozilla/firefox/*/places.sqlite
do echo "${each}"
share|improve this answer

You must log in to answer this question.