PHP Professionals

tech stuff, tips and the occasional rant

Shell tricks (1)

Posted on | December 4, 2008 |

Some shell tricks, most of them interesting for deploying and handling your files:

find files recently modified (say in the last 2 days, -mtime 1):

1
find . -type f -daystart -mtime 1

synchronize an entire directory to a remote server (overwrites everything, remote server has to have rsync installed too):

1
rsync -avzpog yourdir you@remotebox:/remotedir/

other way around:

1
rsync -avzpog you@remotebox:/remotedir/* yourdir/

build a listing of md5 checksums usefull for controlling the integrity of your files later:

1
find ./yourdir/ -type f -exec md5sum {} \; > checksumlisting.lst

use the generated list to check your files’ integrity:

1
md5sum -c checksumlisting.lst | grep -i failed

remove SVN directories from your tree of files:

1
find ./ -name '*svn*' -exec rm -rf {} \;

likewise for CVS directories:

1
find ./ -name '*cvs*' -exec rm -rf {} \;

if you messed up your console because you paged (more, less, head, tail) a binary file, reset your console display:

1
reset

Comments

2 Responses to “Shell tricks (1)”

  1. kakaopor
    December 5th, 2008 @ 6:59 pm

    Hi there!

    I think this little collection is pretty useful.

    Just a little comment: the -a switch for rsync implies the -pog, so you have to use the -a only (much easier to remember -avz only:). (And note that -a does not preserve hardlinks, so if you need to, use -H).

    kakaopor

  2. jonas
    December 8th, 2008 @ 8:12 pm

    You are right,

    -avz stands for: archive mode (symbolic links, devices, attributes, permissions and ownerships are preserved), verbose and (zlib) compressed.

    -pog stands for: preserve permissions, owner and group which is obviously included in the archive mode mentioned above.

    Don’t know why I remember it as -avzpog and why I started doing it like that instead of -avz. Note to self: use -avz.

    cheers
    Jonas

Leave a Reply