Recursive touch command on BusyBox 1.01

0

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.

Jack Sleight

Posted 2011-04-24T17:42:48.827

Reputation: 125

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? – Pricey – 2011-04-24T18:09:13.457

Answers

0

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.

Turbo J

Posted 2011-04-24T17:42:48.827

Reputation: 1 919

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 – 2011-04-24T19:03:06.340

1

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
#!/bin/sh
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.

Erhhung

Posted 2011-04-24T17:42:48.827

Reputation: 111