Find and remove files with pattern in bash
Useful command to remove files that start with "._" (no quotes), for some reason tar command in OS X creates those files and I found an app having problems with them, here is how to get rid of those unnecessary hidden files:
find . -name *._* -exec rm -f {} \;
Find out Ubuntu version from command line
Type the following command on a terminal window:
$ lsb_release -a LSB Version: core-2.0-ia32:... Distributor ID: Ubuntu Description: Ubuntu 12.04 LTS Release: 12.04 Codename: precise
BASH: Rename multiple files with sequential number at end
Spent way too much time trying to do this, hope this help someone else:
i=1;for f in *.jpg; do mv "$f" "newname$i.jpg"; let i++; done
Extract emails from big text file
Fount it here:
perl -wne'while(/[\w\.\-]+@[\w\.\-]+\w+/g){print "$&\n"}' emails.txt | sort -u > output.txt
Simulate load on linux serve with one-line command
Some days ago I needed a quick way to simulate load on a Linux sever. While there are many tools that can do this, all I needed was a simple bash one-line command that can make the CPUs beg for mercy.
What I ended up using is this:
dd if=/dev/zero bs=100M | gzip | gzip -d | gzip | gzip -d | gzip | gzip -d > /dev/null &
Send a few of these to the background and you'll start seeing smoke coming from your server soon.
Bash sequences
A very helpful command I like to use to organize folders is:
for i in {a..z}; do mkdir $i; done
This creates a folder for each letter from "a" to "z".
Howto backup and restore MySQL database with character set intact
If you want to preserve characters like ñ, ó, ç, etc. when migrating a MySQL database use mysqldump to export the database with this options:
mysqldump -u root -p --default-character-set latin1 --skip-character-set <dbname> > mydump.mysql
create the target database with:
mysqladmin -u root -p create <dbname> --default-character-set latin1 --collate latin1_swedish_ci
then restore:
mysql -u root -p --default-character-set latin1 <dbname> < mydump.mysql