Reputation: 137
I'm trying to zip up all .log files in a my log directory. I want to zip each log file individually and keep it in the same directory, then delete the original. I'm somewhat new to using Linux and for loops in Linux. Here is the for loop I'm trying to run
ssh user@SERVER "for i in *.log; do zip -m \"${i%.*}.zip\" \"${i%.*}\".*; done"
What ended up happening is all of my hidden files got zipped up. Like I said, I'm kinda new so, whatever syntax error I made isn't jumping out at me. Any help would be appreciated
Upvotes: 0
Views: 1624
Reputation: 1083
Try this (you were near)
ssh user@SERVER 'for i in *.log; do echo zip -m "\${i/.log/.zip}" "\${i}"; done'
If the output seems correct, remove the echo
Upvotes: 1