/kb

personal knowledgebase

Archive for the ‘cli’ tag

Open Finder for current directory from command line

with one comment

I just learned how to open a Finder window directly from the command line.

open .

Yes, it’s actually that easy, and the open command is quite handy some times. This is from the open man page.

The open command opens a file (or a directory or URL), just as if you had double-clicked the
file’s icon. If no application name is specified, the default application as determined via
LaunchServices is used to open the specified files.

This means that you can actually open anything from the command line with the open command. Go ahead and try it out!

Written by Håvard Grimelid

January 9th, 2009 at 9:41 am

Posted in Shell

Tagged with , ,

Importing a MySQL dump file

with one comment

mysql -h SERVER -uUSER -p DATABASE < DUMPFILE

Written by Håvard Grimelid

January 6th, 2009 at 7:58 pm

Posted in Server

Tagged with , ,

Root partition free space

without comments

du -xh --max-depth=1  /

Written by Håvard Grimelid

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 Håvard Grimelid

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 Håvard Grimelid

May 14th, 2008 at 6:29 pm

Posted in Server

Tagged with , , ,