Page 1 of 1

find and move files in BusyBox

Posted: Sat Nov 27, 2010 11:17 am
by julz
Hello,

I would basically like to write a little script a bit like this (bash) :

Code: Select all

find . -name '*test*' -exec mv {} / \;
But since I don`t have bash installed on the NAS, just ash ( I think ), I have to do something like this :

Code: Select all

find . -name '*test*' | xargs mv {} /test;
I get this error :


mv: unable to stat `./test1/{}': Not a directory

Obviously I`m not passing the arguments correctly, anyone knows how to do that properly in Busybox ?


Cheers,

EDIT: or maybe how I can run a bash script from ash :)

Re: find and move files in BusyBox

Posted: Sat Nov 27, 2010 3:29 pm
by micke
julz wrote: But since I don`t have bash installed on the NAS, just ash ( I think ), I have to do something like this :
This has nothing to do with the shell. Both find and xargs are busybox commands with a limited number of options.
julz wrote:

Code: Select all

find . -name '*test*' | xargs mv {} /test;
Wouldn't work with a "normal" xargs either. xargs always puts the arguments at the end. Add -t to xargs and you will see that the command you are trying to run is (with a test1 file in the directory),

Code: Select all

mv {} /test ./test1
You would have to add -i for this to work, but there is no -i option in busybox's xargs.

Install Optware and the findutils ipkg package (for find and xargs) and maybe also coreutils for many other shell commands and don't try to use the limited busybox commands, which in some cases are completely broken on the NAS (e.g. the install command).

/Mike

Re: find and move files in BusyBox

Posted: Sun Nov 28, 2010 12:21 pm
by julz
Hey Micke,

Thanks for your help, I actually ended writing a little python script, that was easier :)

cheers,
J