Monday, September 21, 2009

Replace/overwrite files in a hierarchy

I needed to replace a file in a hierarchy with a new version:-
Here is a script which works in most shell variants bash, zsh etc but apparently not csh.

for f in */include/dbcommon.php; do;cp dbcommon.php $f; done

Labels: , ,

Thursday, August 06, 2009

Useful ZSH Commands

vi *(.om[1]) # vi newest file
vi -p *(.om[1,3]) # open 3 newest files in tabs (gvim)
vi *(m0) # re-edit all files changed today!
ls *(^m0) # files NOT modified today
ls -l *(m4) # list files modified exactly 4 days ago
vi **/main.php # where ever it is in hierarchy
ls (x*~x[3-5]) # list files x* except x3 to x5
vi !$ # vi last parameter
vi !-2:2 # second parameter of second but last command
vi !$:r.php # vi last parameter but change extension to .php
^mian^main # modify previous command (good for correcting typos)
^php^cfm # modify previous command replace php by cfm

more zsh tips and tricks here

Labels: ,

Monday, November 24, 2008

Download "Invisible" .htaccess and .htpasswd dot files from your server

For some reason (security?) some FTP servers don't allow you to see dot files such as .htaccess and .htpasswd , this prevents you downloading them as well. Which is somewhat of a nuisance if you are trying to back them up or debug them.

Here is a zsh script I wrote to get round this, note you still need to enter your ftp login details, so this is not a hack.

#!/bin/zsh
# download "invisible" .htaccess .htpasswd files
autoload -U zfinit
zfinit
zfparams www.website.co.uk userid password # enter your own details here
zfopen
zfls -ad
zfget .htaccess
zfget .htpasswd

Labels: , ,

Wednesday, January 30, 2008

Do you know ZSH?

I previously used Bash for scripting but now prefer ZSH. I've developed my own set of primitives so for instance

> cp NF ND

Will copy the newest file in the directory to the newest sub-directory.
NF & ND are global aliases (global means can be used any where in command line)


alias -g ND='*(/om[1])' # newest directory
alias -g NF='*(.om[1])' # newest file

zsh has many wonderful features, a small number are listed here:-

http://www.successtheory.com/tips/zshtips.html

Labels: