/kb

personal knowledgebase

Archive for May, 2008

Create a new MySQL-user with all privileges

without comments

GRANT ALL PRIVILEGES ON thedatabase.* TO 'theusername'@'localhost'
	IDENTIFIED BY 'thepassword' WITH GRANT OPTION;

UPDATE 20080916: Skip the last line if the user exists.

Written by hgrimelid

May 17th, 2008 at 7:26 pm

Posted in Server

Tagged with

Root partition free space

without comments

du -xh --max-depth=1  /

Written by hgrimelid

May 17th, 2008 at 7:21 pm

Posted in Shell

Tagged with ,

On using find

without comments

find is an extremely powerful command. In order to leave the directory matching *DIRECTORY* out from your search for .txt-files:

find . -path '*DIRECTORY*' -prune -o -iname '*.txt' -print

If you’re using xargs together with find and xargs complains about file names with spaces, use:

find . YOURFINDOPTIONSHERE -print0 | xargs -0 rm -rf

Finding files larger than a certain limit:

find . -size +200M -print0 | xargs -0 ls -lh

Deleting the complementary files:

find . ! -name "*.mp3" -delete

Courtesy of HÃ¥kon.

Please note that these commands pertains to the BSD find as on Mac OS 10.5.

UPDATE 20080517: Looking for file size
UPDATE 20080602: Added deleting complement

Written by hgrimelid

May 15th, 2008 at 12:49 pm

Posted in Shell

Tagged with , , , ,

Backup a MySQL database with mysqldump

without comments

It’s very easy, but I always have to look it up.

mysqldump --opt -u USERNAME -p -h HOST.HOST.COM DATABASE_TABLE > DUMPFILE.sql

Written by hgrimelid

May 14th, 2008 at 6:29 pm

Posted in Server

Tagged with , , ,

Some useful Vim-commands

without comments

There are numerous pages and blog posts about Vi and Vim out there so here’s my small contribution. Here are some less frequently used commands that tends to be useful from time to time:

Delete lines patching pattern
:g/pattern/d
Go to position previously modified
g;
Go to next modified position in change list
g,
Create bookmark in file
mLETTER
Go to bookmark
'LETTER
Change highlighted text to upper case
gU
Open file under cursor
gf
Coopy text mathich pattern to register a
:/pattern/yank A
Paste text from register a
"ap
Reduce split window size
C-w -
Increase split window size
C-w +
Make split windows equally big
C-w =

Written by hgrimelid

May 14th, 2008 at 12:36 pm

Posted in Editors

Tagged with , , ,

Prettify print_r output

without comments

By putting print_r() statements enclosed by html pre-tag, the output is quite a lot more readable.

Written by hgrimelid

May 7th, 2008 at 6:21 pm

Posted in Programming

Tagged with ,