Re: find exec rm

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 13Jul2017 11:33, bruce <badouglas@xxxxxxxxx> wrote:
i'm missing something. thoughts/comments?

trying to do a rm with find/exec.

ssh  crawl_user@1.2.3.4 " rm -f '/cloud_nfs/*hash*.dat' ;  find
/cloud_nfs  -name '*austincc*master*book*.dat' -exec rm {} \; rm -f
'/cloud_nfs_fetch/*hash*.dat' ; "

i get
find: paths must precede expression: rm
Usage: find [-H] [-L] [-P] [-Olevel] [-D
help|tree|search|stat|rates|opt|exec] [path...] [expression]

can't seem to see my error...

however, if I remove the last rm -- the find/exec/rm works..

The argument to -exec is a command and arguments; the command is invoked directly from find; the shell is _not_ inolved. You're trying to (half) treat it as a shell command; there's no shell syntax use here because it never goes near the shell.

So you're just asking to invoke "rm {}" and then find is seeing the following "rm" when it is expecting another -blah operator.

Get your command right, interactively, on the remote machine first. Trying to debug this via an:

 ssh ... "blah"

will only make debugging even harder.

What should your remote command be?

It currently looks a bit like:

rm -f '/cloud_nfs/*hash*.dat'
find /cloud_nfs -name '*austincc*master*book*.dat' -exec rm {} \; rm -f '/cloud_nfs_fetch/*hash*.dat'

Did you want:

rm -f '/cloud_nfs/*hash*.dat'
find /cloud_nfs -name '*austincc*master*book*.dat' -exec rm {} \;
rm -f '/cloud_nfs_fetch/*hash*.dat'

First up, by putting quotes around your /cloud_nfs paths, you prevent the globs from working - they're trying to remove the literal path '/cloud_nfs/*hash*.dat', not all the files the glob would match. Drop the single quotes.

Note that you _do_ need the quotes in the find command because you are asking find itself to do the match, so the glob string must get to find untouched. Therefore the quotes to _prevent_ the glob being expanded.

Anyway, get your command correct directly on the remote host. Then construct the "ssh crawl..." incantation as a second step.

Also, you may find turning on the -x shell option _very_ useful for debugging remove commands. Thus:

 ssh crawl_user@1.2.3.4 "set -x; shell command here ..."

It will should you the precise commands dispatched at the far end, which goes a long way towards figuring out what you may have got wrong.

Cheers,
Cameron Simpson <cs@xxxxxxxxxx>
_______________________________________________
users mailing list -- users@xxxxxxxxxxxxxxxxxxxxxxx
To unsubscribe send an email to users-leave@xxxxxxxxxxxxxxxxxxxxxxx



[Index of Archives]     [Older Fedora Users]     [Fedora Announce]     [Fedora Package Announce]     [EPEL Announce]     [EPEL Devel]     [Fedora Magazine]     [Fedora Summer Coding]     [Fedora Laptop]     [Fedora Cloud]     [Fedora Advisory Board]     [Fedora Education]     [Fedora Security]     [Fedora Scitech]     [Fedora Robotics]     [Fedora Infrastructure]     [Fedora Websites]     [Anaconda Devel]     [Fedora Devel Java]     [Fedora Desktop]     [Fedora Fonts]     [Fedora Marketing]     [Fedora Management Tools]     [Fedora Mentors]     [Fedora Package Review]     [Fedora R Devel]     [Fedora PHP Devel]     [Kickstart]     [Fedora Music]     [Fedora Packaging]     [Fedora SELinux]     [Fedora Legal]     [Fedora Kernel]     [Fedora OCaml]     [Coolkey]     [Virtualization Tools]     [ET Management Tools]     [Yum Users]     [Yosemite News]     [Gnome Users]     [KDE Users]     [Fedora Art]     [Fedora Docs]     [Fedora Sparc]     [Libvirt Users]     [Fedora ARM]

  Powered by Linux