Tag Archives: Ubuntu

My Top 10 Ubuntu Aliases

aka: The Ultimate List of Ubuntu Aliases

Okay, maybe this isn’t the ultimate list, and maybe it’s more than 10, but this is my list of essential, must-have aliases for Ubuntu (or any version of Linux). Aliases are “shortcuts”. For example, if you’re at the command prompt and want to exit, you normally type exit. But I have an alias for the letter e to exit. I cut my typing by 75%!! Do this all throughout your workflow and you’ll seriously wonder how you ever lived without it. Backup your aliases.

By adding these aliases, I have turned 277 characters of typing down to just 35. That’s a reduction of over 87%!!! Finally, I can leave work at 10am. :)

If you want to use an alias in Ubuntu Linux, insert these commands (or any other commands that speed up your workflow) at the bottom of your .profile or .bashrc files:

    alias sp=’sudo pico’
    alias la=’ls -alh’
    alias m=’mutt’
    alias e=’exit’
    alias cdw=’cd /var/www/’

      alias cdb=’cd /var/www/brockangelo/’
      alias cda=’cd /var/www/angeloarchive/’ (if you host multiple websites, replace the “a” with a website identifier. aka, photoshopsamurai = ps)
      alias cdps=’cd /var/www/photoshopsamurai/’

    alias cdn=’cd /usr/local/nagios/etc/’
    alias nr=’sudo /etc/init.d/nagios restart’
    alias ar=’sudo /etc/init.d/apache2 restart’
    alias coffee=’cat > /var/www/brockangelo/coffees.txt’ (I used to have a coffee-counter on my website and I would update the number of coffees my espresso machine had made – you can use this to replace the contents of a text file quickly)
    alias s=’sudo’
    alias aa=’/home/brock/scripts/add_alias.sh’ (I created a shell script to add new aliases by just typing aa – leave a comment if you’d like to download the script)

And here is the code for the shell script:

    echo Enter the shortcut, or alias, you want to use:
    read SHORTTEXT
    echo Now enter what text you want it to replace:
    read LONGTEXT
    echo “alias $SHORTTEXT=’$LONGTEXT’” >> ~/.profile
    echo “alias $SHORTTEXT=’$LONGTEXT’ was added to your profile. Changes effective after logout/in.”

Delete Comment Spam using a Cron Job

Delete Comment Spam using a Cron Job

WordPress catches all of the comment spam, but it doesn’t seem to delete it often enough. If you have a high traffic site, this can become megabytes in your database. Bleh. I don’t have a high traffic site, but I sync my databases off-site everyday and spam wastes my bandwidth. So I delete all the comments marked as spam automatically each day using a scheduled cron job so that I never even have to see it. Could I possibly delete a real comment? Yes. Does the convenience of never even knowing about comment spam outweigh the risk? You bet.

Create a bash script in your scripts folder by typing this at the command prompt:

sudo pico /home/brockangelo/scripts/del_spam.sh

sudo: elevate privileges
pico: use your editor of choice
/home…/scripts/: wherever you keep all your bash scripts
del_spam.sh: name it something obvious

By the way, bash scripts are as easily made as windows batch files. You just put in the code and put a .sh at the end. Inside “del_spam.sh” add the following:

mysql -u username -ppassword -e "delete from wp_comments where comment_approved='spam';" brockangelo

Where “brockangelo” is the name of the database. Repeat this line for each WordPress site you host. Then you need to set this up as a cron job and schedule it for once a night. Or, you can download my plugin that deletes spam daily. Delete Spam Daily plugin.

By the way, the username and password format in that command you see above looks wrong, but it is typed correctly. You put “-u (space) username” then you squish the “-p” and “password” together like this “-u username -ppassword”.

How to Add Uploaded Media to WP-DownloadManager

WARNING: All of the recommendations in this post work off of a test database. The following commands could damage your live site if not tested first. Always work off a test site, then perform a database backup before doing any of these things.

I was faced with a challenge at work this week: I wanted to track how many downloads our forms were getting on the company intranet (built on WordPress). I had already uploaded over one thousand forms to the site. I needed an upload tool that would be able to look at all of the forms and other media that we have accumulated. Unfortunately, none of the download counter plugins for WordPress will look add existing media, and they all want you to upload your forms (or media) through their “Add download” button.

Well, if I’d uploaded only a couple of forms, this wouldn’t be a problem. But since I was dealing with one thousand, I needed a way to import existing uploads into the new download counter. This would have to be done in MySQL.

I looked at download counters on wordpress.org and found one that I liked: WP-DownloadManager. There seem to be quite a few of them, including WP-DownloadCounter (which I also liked) but I chose this one simply because it had been around longer and had a very high rating.

WP-DownloadManager has a way to import existing forms from the management page, but they have to be done one at a time, and you have to manually type all of your titles over again. This would take way too long. So I came up with a way to migrate all of my uploaded form titles and filenames to the WP-DownloadManager’s database.

How to Bulk Import into a MySQL Database

This tutorial shows you how to take a large number of values and import them as cells in your MySQL database.

Here is a typical scenario: we have a list of account numbers at work that tell us when a patient is in network. If a patient is out-of-network when they come to our clinic, they’ll have a hefty bill to pay out of pocket; so the staff searches against a MySQL database that I setup to determine if they are in-network or not.

This database has over 8,000 account numbers in it. From time to time, new account numbers need to be added to the database. I will get an e-mail with anywhere from three to fifty new account numbers to add. If it is a small number, I simply go into PhpMyAdmin and manually add the rows. But if there are more than ten new account numbers, it would take a long time to enter them all by hand. So here are two ways to do it.

Method #1

Create a text file with the new account numbers in it, each on it’s own line. It should look like this:


Save this text file and upload it to your server where the SQL database resides. If you are on a unix server, the full path would look like this:


With it saved to the server, we need to execute SQL code in a database editor like PHPMyAdmin or using the Webmin MySQL Database Server software. Inside this software, you’ll want to browse into the database (in this case, let’s call it “intranet”). Inside the database, you’ll have a table for all of your account numbers (let’s call this table “accounts”).

You’ll want to execute SQL code. Most software packages have an option to “Execute SQL” which works a lot like a command line. In this box, you’ll execute the following:

LOAD DATA LOCAL INFILE '/home/username/accounts.txt' INTO TABLE accounts FIELDS TERMINATED BY 'r' (numbers, id)

Here is what all of that means:

LOAD DATA LOCAL INFILE: This simply means to pull the data from the text file that we uploaded from the server and to use the data for our import.

‘/home/username/accounts.txt’ : This would be the full path and filename of the text file that has all of your new account numbers. The username value refers to the username on the unix server where the file was uploaded. If you are on a Windows server, it would look more like 'C:Documents and SettingsusernameMy Documentsaccounts.txt' or something similar.

INTO TABLE accounts : This simply means that we want to insert the data into our “accounts” table in our database.

FIELDS TERMINATED BY ‘r’ : If you are familiar with Excel, this is like your delimiter. Since I have all of the values on their own line, I use ‘r’ (which refers to a carriage return, or a new line). If you separate them all by commas, you would just use ‘,’ instead.

(numbers, id) : These are the column names inside the table where the data will be stored. If you were to open my table, you would see “id” first, then “numbers”. The “id” field is the primary key assigned to the row, and the “numbers” field is where my account numbers are. The “numbers” field is listed first because SQL will put the data in the first field. ID will then auto increment.

Method #2

The second method is to paste the new data into your MySQL editor (instead of uploading a text file).