Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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'm trying to write a bash script that will run on my QNap NAS to touch a directory recursively. I have this:

find $1 -exec touch {} +

However, find that comes with BusyBox 1.01 doesn't support the -exec argument, here are the docs:

BusyBox v1.01 (2011.02.08-16:24+0000) multi-call binary

Usage: find [PATH...] [EXPRESSION]

Search for files in a directory hierarchy.  The default PATH is
the current directory; default EXPRESSION is '-print'

EXPRESSION may consist of:
    -follow     Dereference symbolic links.
    -name PATTERN   File name (leading directories removed) matches PATTERN.
    -print      Print (default and assumed).

    -type X     Filetype matches X (where X is one of: f,d,l,b,c,...)
    -perm PERMS Permissions match any of (+NNN); all of (-NNN);
            or exactly (NNN)
    -mtime TIME Modified time is greater than (+N); less than (-N);
            or exactly (N) days

So, is there another approach I could use instead, to achieve the same goal? Thanks.

share|improve this question
What shell are you in?/What do you have available? I would hope that one of those would have for or read to take the list from find's -print? – PriceChild Apr 24 '11 at 18:09
up vote 0 down vote accepted

Your busybox may have the xargs command:

find $1  | xargs touch

This command has the nice effect of being able to call e.g. touch with multiple file names at once, thus shorting the net run time quite a bit.

share|improve this answer
Yes, do have xargs. Seems to work, but some files have ' characters in the file names, and I get "xargs: unmatched single quote". Any ideas? – Jack Sleight Apr 24 '11 at 19:03

I have had the exact same need, and, after experimenting with the differences in the BusyBox implementation, have created this 1-line bash script:

[/share/MD0_DATA] # cat ./touch_all_folders
find -type d | sed 's/[^[:alnum:].\/_-]/\\&/g' | xargs touch -c

You can customize the script with parameters as you see fit. The sed command escapes all the special filename characters.

share|improve this answer

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.