Archive for the ‘cli’ tag
Open Finder for current directory from command line
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!
Importing a MySQL dump file
mysql -h SERVER -uUSER -p DATABASE < DUMPFILE
Root partition free space
du -xh --max-depth=1 /
On using find
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
Backup a MySQL database with mysqldump
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