Handy Linux Commands

Get the size of the folders in any directory

du -sh folder_location/*

Get the size of folders in the current directory

sudo du -chax --max-depth=1 . | grep -E "M|G"

Search for content of a file from the command line

grep [--include=file_pattern.extension] -rnwl "matching pattern"
http://stackoverflow.com/questions/16956810/finding-all-files-containing-a-text-string-on-linux

Create a new SVN Repo

sudo svnadmin create /svn/repos/repo_name
sudo chown -R www-data:www-data /svn/repos/repo_name

Remove Directory and Contents

rm -r mydir

List CPU Usage of running processes

top

Get Wireless Signal Information

iwconfig

will save in /tmp/file_list_$FOLDER an alphabetically ordered list of all the files inside $FOLDER, complete with the corresponding sub-folders

find $FOLDER -type f | cut -d/ -f2- | sort > /tmp/file_list_$FOLDER

Display all processes accessing a folder or drive (source)

sudo fuser -mv /folder

zpool change mount location (source)

zfs set mountpoint=/myspecialfolder mypool

lsof command to get the process ID of the process holding the lock files (source)

sudo lsof /var/lib/dpkg/lock
sudo lsof /var/lib/apt/lists/lock
sudo lsof /var/cache/apt/archives/lock

Get all processes running “apt” and kill those processes (source)

ps aux | grep -i apt
sudo kill -9 <process_id>

How to Migrate DNS Servers from Old Hosting

When migrating servers it’s best to leave a few months overlap on your old hosting contract. It’s a pain to pay double for a while but it’s critical to preventing downtime.

The first thing to do is get all your files moved over to the new server and test to make sure everything is working the same. Once you are satisfied that your new server is operating properly you can do a “full test run” with the DNS server configurations.

On your old hosting remove the DNS A Records for your old hosting server. It will typically be in there by default. Add a new custom DNS A record pointing to your new server.

This effectively redirects all traffic from your old hosting to the copy on the new hosting. Sometimes it takes as much as 48 hours for these changes to go into effect but in my experience, 15 minutes is more reasonable. Now all the traffic is headed to your new server and since you tested ahead of time (right??) everything is working as it should be.

Now you can migrate your domain names over to the new hosting provider without fear of 48 hours of downtime when your site and apps will be unreachable.