Archive for the ‘Shell’ Category
SSH aliases
In ~/.ssh/config add the following:
Host ALIAS HostName DOMAIN User USERNAME Port PORT_NUMBER
Compile Vim in Snow Leopard
./configure –enable-pythoninterp –with-macsdk=10.6
Git: Start a new branch after making changes
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.
Exclude several files or directories from tar
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
Make SSHKeychain work in Leopard
Here’s how I set up SSHKeychain on my Mac:
- Modify the package content as described
- Add stuff to .bashrc/.profile
- Add keys to SSHKeychain: Preferences > SSH Keys
- Check Manage (and modify) global environment variables (this probably has no effect, ref 2.)
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!
Bash shell prompt colors
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.
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
grep through several files
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.