Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Suppose we have two servers 'A' and 'B'.

Server B:

Directory structure: /a/b/c/

The above directory has the files below:

2016xzy
2016abc
2016pqr
2015ghj
  1. I want to delete all files which have names starting with 2016 from server B (/a/b/c/).

  2. The shell script should be on server 'A'.

  3. The pattern (i.e. 2016) should be taken as a variable in the shell script.

share|improve this question
    
"from one server to another" - should be "from" another? Using "to" sounds like you want to move the files. (?) – w3d yesterday

Just do, from server_A:

ssh server_B 'rm -- /a/b/c/2016*'

Passing starting pattern as variable:

var=2016
ssh server_B "rm -- /a/b/c/${var}*"
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.