/kb

personal knowledgebase

Archive for the ‘Shell’ Category

SSH aliases

without comments

In ~/.ssh/config add the following:

Host ALIAS
HostName DOMAIN
User USERNAME
Port PORT_NUMBER

Written by hgrimelid

June 18th, 2010 at 10:02 am

Posted in Server,Shell

Tagged with ,

Compile Vim in Snow Leopard

without comments

./configure –enable-pythoninterp –with-macsdk=10.6

via Chris Moyer: OSX, Vim, and Python.

Written by hgrimelid

April 28th, 2010 at 11:01 am

Posted in Editors,Programming,Shell

Tagged with ,

Git: Start a new branch after making changes

without comments

Sometimes I realize that my latest changes actually should belong to another branch than the one I’m currently working on. The easy way to add the changes to a new branch is to use the stash command.

[… changes …]
git stash
git stash branch name_of_new_branch
git commit []
git push origin name_of_new_branch

Ref. git stash.

Written by hgrimelid

April 23rd, 2010 at 12:39 pm

Posted in Programming,Shell

Tagged with

Exclude several files or directories from tar

without comments

It’s very useful to be able to exclude certain files or directories when using tar. Here’s how I did in Leopard:

tar czvf FILENAME.tgz --exclude={.svn,wiki*,static} FILES_OR_DIRS_TO_TAR

Written by hgrimelid

August 9th, 2009 at 4:08 pm

Posted in Shell

Tagged with , , ,

Make SSHKeychain work in Leopard

without comments

Here’s how I set up SSHKeychain on my Mac:

  1. Modify the package content as described
  2. Add stuff to .bashrc/.profile
  3. Add keys to SSHKeychain: Preferences > SSH Keys
  4. Check Manage (and modify) global environment variables (this probably has no effect, ref 2.)

Written by hgrimelid

June 22nd, 2009 at 10:43 am

Posted in Shell

Tagged with , , , ,

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 , ,

Bash shell prompt colors

without comments

Here are the colors available for use in the bash shell prompt:

Black 01;30
Blue 01;34
Brown 01;33
Cyan 01;36
Green 01;32
Red 01;31
Pink 01;35
Yellow 01;33

This is my shell prompt:

PS1='\[\033[01;32m\]\u@\h \[\033[01;35m\]\W \$ \[\033[00m\]'

Which produces output on the form user@computer DIRECTORY $. I use different colors for different computers/users.

Written by Håvard Grimelid

August 8th, 2008 at 12:25 am

Posted in Shell

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 , , , ,

grep through several files

without comments

By adding option -H to the grep command, the filename will be output together with the matching line:

grep -i -H TEXT_TO_SEARCH_FOR

-i turns on ignore case.

Written by Håvard Grimelid

April 10th, 2008 at 10:13 am

Posted in Shell

Tagged with , , ,