find and move files in BusyBox

Discussion about using NAS on Linux and Unix OS.
julz
Starting out
Posts: 18
Joined: Tue Aug 25, 2009 1:04 pm

find and move files in BusyBox

Postby julz » Sat Nov 27, 2010 11:17 am

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 :)

micke
Experience counts
Posts: 1363
Joined: Sat Feb 06, 2010 2:42 pm
Location: Taipei, Taiwan

Re: find and move files in BusyBox

Postby micke » Sat Nov 27, 2010 3:29 pm

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

julz
Starting out
Posts: 18
Joined: Tue Aug 25, 2009 1:04 pm

Re: find and move files in BusyBox

Postby julz » Sun Nov 28, 2010 12:21 pm

Hey Micke,

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

cheers,
J


Return to “Linux & Unix (NFS)”

Who is online

Users browsing this forum: No registered users and 1 guest