deleting with wildcards over ssh ... how ?

Bill Moran wmoran at collaborativefusion.com
Wed Aug 30 15:13:24 UTC 2006


In response to Ensel Sharon <user at dhp.com>:

> 
> I want to delete some remote files with a wildcard, running 'rm' over ssh.
> 
> The obvious syntax doesn't work at all - it doesn't even make an ssh
> connection - I think it is interpreting the wildcard locally:
> 
> # ssh user at host rm -rf /some/testdir/*
> ssh: No match.
> 
> Then, these combinations of single and double quotes:
> 
> ssh user at host 'rm -rf /some/testdir/*'
> 
> ssh user at host rm -rf '/some/testdir/*'
> 
> ssh user at host 'rm -rf "/some/testdir/*"'
> 
> All connect over ssh, and produce no errors, but the remote files are
> still there - nothing was deleted.
> 
> So what is the _right_ way to do this ?

Most of those should work.  What are the names of the files you are
trying to delete?  By default, * does not match filenames beginning
with a '.'.  The best command line would be:
ssh user at host 'rm -rf /some/testdir/*'
which will cause the local machine to send the command without expanding
the * first.  The * should then be expanded on the remote system.  Try:
ssh user at host 'echo /some/testdir/*'
to see if it's doing what you expect.

-- 
Bill Moran
Collaborative Fusion Inc.


More information about the freebsd-questions mailing list