Terminal Cheatsheet
Useful tidbits for OSX and other *nix systems…
To display your path:
$PATH(each directory in the path is separated by a colon)
To display your shell:
$SHELLTo modify your path (add a directory):
echo 'PATH=$PATH:usr/local/bin' >> ~/.bash_profile source .bash_profile
Typical configuration files
.bash_profile
.profile
.cshrc
To reload your modified profile:
. ./.profilesource ~/.profile
source ~/.bash_profile
To create symbolic links:
ln -s original_path symlink_name
To remove symbolic links:
cd to directory rm -r symlink_name
To see which environment variables are defined in your current shell:
env
setenvTo set an environment variable (modify your config file):
setenv VAR value (tcsh) export VAR=value (bash)
To unset an environment variable:
unset VAR(tcsh and bash)
To copy files from one location to another:
cp current_location new_locationTo copy directories from one location to another:
cp -r current_location new_location
To add a temporary host name to your hosts file
sudo echo "xxx.xxx.xxx.xxx domain_name.com" >> /private/etc/hosts
To remove a temporary host name from your hosts file
cd /etc/ perl -e 'open(F, "hosts"); @array = (); close(F); open(FH, "> hosts");print FH @array[0..($#array - 1)]; close(FH);'
To access a path that includes whitespaces and is stored in an environment variable:
"$ENV_VAR"/somedir/somefile
To remove alias arrows in Finder:
cd /System/Library/CoreServices/CoreTypes.bundle/Contents/Resources sudo mv AliasBadgeIcon.icns AliasBadgeIcon_OFF.icns killall Finder
To resotre alias arrows in Finder:
cd /System/Library/CoreServices/CoreTypes.bundle/Contents/Resources sudo mv AliasBadgeIcon_OFF.icns AliasBadgeIcon.icns killall Finder
To show hidden files in Finder:
defaults write com.apple.Finder AppleShowAllFiles YES killall Finder
To hide files in Finder:
defaults write com.apple.Finder AppleShowAllFiles NO killall Finder
To make directory paths visible across the top of a Finder window: Mac OS X Leopard (version 10.5)
defaults write com.apple.finder _FXShowPosixPathInTitle -bool YES killall Finder
To remove the glass effect from your dock (darkens the dock):
defaults write com.apple.dock no-glass -boolean NO; killall Dock
To restore the glass effect to your dock:
defaults write com.apple.dock no-glass -boolean YES; killall Dock
To disable Dashboard:
defaults write com.apple.dashboard mcx-disabled -boolean YES killall Dock
To restore Dashboard:
defaults write com.apple.dashboard mcx-disabled -boolean NO killall Dock
To tarball a website (xfer to another server)
1. on the original machine
cd / tar -cpzf filename.tar.gz *
2. on dest machine
cd / wget http://oldserver.com/filename.tar.gz wget username:password@http://oldserver.com/filename.tar.gz (for authentication) tar -xzf filename.tar.gz
To backup MySQL databases
mysqldump --add-drop-table -u dbusername -p dbname > dbname.bak.dump
or
mysqldump --opt -u dbusername -p dbname > dbname.bak.dump
To restore MySQL databases
mysql -u dbusername -p dbname < dbname.bak.dump
To restart Apache (2.0)
apachectl -k gracefulTo stop Apache (2.0)
apachectl -k stopTo restart Apache (1.x)
service httpd restart
To stop Apache (1.x)
service httpd stop service httpd start
To restart the server
shutdown now -rTo get hardware architecture info
uname -a
To patch a file
patch < path/file.patch
To patch a file and backup the original
patch < path/file.patch -b
To test patch a file before actually applying the patch
patch < path/file.patch --dry-run
To reverse a file patch
patch -p0 -R < path/file.patch
To relocate an SVN repository
svn switch --relocate svn://host/repos \ http://host/repository
To backup an SVN repository (using gzip for compression)
svnadmin dump /svn_parent_path/repos > svn_repos_dump_date gzip -9 svn_repos_dump_date
To break an SVN repository lock
svn unlock --force http://host/repository/file
To change your login background picture
cd /System/Library/CoreServices/ sudo mv DefaultDesktop.jpg DefaultDesktop.jpg.bak sudo cp /Path/to/your/new/background.jpg DefaultDesktop.jpg
To convert an ICNS icon file to a PNG
sips -s format png /path/to/someIcon.icns --out /path/to/newImage.png
To highlight stack items on hover (NOTE: change “yes” to “no” to revert)
defaults write com.apple.dock mouse-over-hilte-stack -boolean yes killall Dock


