-1

I have a website in CentOS which uses SVN to update and commit.

I want to write a shell script by crontab to auto run schedule work.

I have test a SVN command, svn status | grep ^?
It shows me results like below:

M index.php<br/>
M data/config.php<br/>
? date/aaa.php<br/>
? images/bbb.php<br/>
? images/product1.jpg<br/>
? images/product2.jpg<br/>
? themes/ccc.php<br/>
? themes/index.html<br/>
? temp/compiled/index.php<br/>
? temp/compiled/article.php<br/>
? temp/compiled/footer.php<br/>

I write a SVN command which can delete all unversion and modify php file, like below:

svn status --no-ignore | grep ".php$" | sed 's/^? //' | xargs rm -rf

I want to write a shell script that can help me:

  • delete the unversion file, except modify file
  • only delete php file
  • excepte file ine temp folder

please help me, thanks all

aheze
  • 24,434
  • 8
  • 68
  • 125
Breakgod
  • 3
  • 3

1 Answers1

0

Use grep with the option -v to exclude file paths under temp. To make the command safer I would also skip -r and -f in the rm command:

svn status --no-ignore | grep '^?.*\.php$' | grep -v '^? *temp/' | sed 's/^? *//' | xargs rm
August Karlstrom
  • 10,773
  • 7
  • 38
  • 60
  • Remember that `grep 'x' | sed 's/y/z/'` can be refactored to `sed -n '/x/s/y/z/p'`. You can also easily get rid of the last `grep` with a similar refactoring. See also [useless use of `grep`.](http://www.iki.fi/era/unix/award.html#grep) – tripleee Oct 29 '20 at 17:53
  • @tripleee Apart from conciseness and efficiency we also need to consider readability for someone who is not a sed expert (like me). Another readable alternative is to use awk. – August Karlstrom Oct 29 '20 at 18:45
  • I've a computer which is windows system. How to do the same work in windows bat? – Breakgod Nov 06 '20 at 01:14
  • @Breakgod See https://stackoverflow.com/questions/127318/is-there-any-sed-like-utility-for-cmd-exe – August Karlstrom Nov 06 '20 at 09:00
  • I've read sed, but I don't have any idea to write this command . – Breakgod Nov 09 '20 at 08:05
  • @Breakgod Here are some useful alternatives: https://stackoverflow.com/questions/239340/automatically-remove-subversion-unversioned-files/239358 – August Karlstrom Nov 09 '20 at 09:02