My digital playground

Creating a “bash alias” with an argument

Filed under: Uncategorized — Andre @ 14:41 September 16th, 2009

While setting up and testing the anti virus/spam filter of a mail server I usually send a lot of “test spam” to myself and that involves a pretty long line that needs to be typed in every time, and changed for every mail account i test. I want to make an alias for this using an argument containing the email address, but bash makes it hard if not impossible to do so with an alias. Fortunately it allows you to create an function instead.

The command for sending a “GTUBE” test spam message is

sendmail john@example.com < /usr/share/doc/spamassassin/examples/sample-spam.txt

To make this easier I wanted to make an alias for it, so I can type sendspam <email -address> to send it. And as I mentioned earlier bash don’t allow you to use arguments in aliases. But making a function is just as easy. Add the following line in ~/.bashrc

sendspam () { sendmail "$1"  < /usr/share/doc/spamassassin/examples/sample-spam.txt; }

After the next login you will now be able to use the following command to send a test spam message

sendspam john@example.com

Check MD5 sums for all files in folder with one command

Filed under: Uncategorized — Andre @ 15:01 September 6th, 2009

I came over a simple but genius one-liner for the Linux shell to check the MD5 sum of all files in a folder. It will create a file.md5 containing the checksum just like on the FTP servers.

for c in ./*; do md5sum $c > $c.md5; done

and to list all files with the checksum just use

cat *.md5