Category: bash

rss

Different ssh port with rsync

If you want to to backup from/to an ssh server and this server does not run on 22 as port, you can use this workaround:

1
rsync -r -e 'ssh -p 4321' user@example.org:/home/user/test backup -v

This will sync from the host user@example.org (by using ssh and port 4321) the folder /home/user/test to the folder backup on your local harddisk.

In bash By DracoBlue @ 21:09 16.09.2010

bash tip: for each line in a file

When you want execute an action on a set of files (all, which contain testfile), this technique is pretty straight forward:

1
2
3
4
for line in `find . | grep "testfile"`
do
rm "$line"
done

But this actually does not work, if the file name contains spaces!

In this cases the "while read"-construct is failsafe:

1
2
3
4
find . | grep "testfile" | while read line
do
rm "$line"
done
In bash By DracoBlue @ 17:51 05.04.2010

Change recursive CVS repository information on commanline

You can easily apply a new "Root"-file for a recursive checked out repository structure with the following line (assuming, that you don't have any files called "CVS/Root" except the CVS/Root).

1
find . | grep "CVS/Root" | while read LINE; do echo "$LINE:";cp /home/dracoblue/Root $LINE; done

In this example /home/dracoblue/Root holds the updated Root-File and the command line is executed in the directory which you want to change recursively.

In open source, Articles, Linux & bash By DracoBlue @ 11:12 07.08.2008