Bash 将行附加到文件

echo "<string to append>" >> <file>

#Example:

echo "My string" >> /home/user/myfile.txt

Bash OsX将Dock定位在顶部

Dock Top
defaults write com.apple.Dock orientation top

Dock Right
defaults write com.apple.dock pinning end

Bash Alias用于快速备份

Some might rather have backup put key files somewhere else ie in .backup or /backup 


You could do that pretty easily too... 
Code:

bu () { cp $1 /backup/${1}-`date +%Y%m%d%H%M`.backup ; } 

This would put all files into /backup/ 

Code:

bu () { cp $1 ~/.backup/${1}-`date +%Y%m%d%H%M`.backup ; } 

This would put all the files into ~/.backup (in your home directory) 

this would require that you are IN the directory of the file you want to backup. You would move the file with the bu FILENAME ...... you could not use the /path/filename method like i listed above.

Here's a twist to so you can maintain your backed-up file in the same directory structure in your .backup directory 
Code:

bu () 
{ 
    if [ "`dirname $1`" == "." ]; then 
        mkdir -p ~/.backup/`pwd`; 
        cp $1 ~/.backup/`pwd`/$1-`date +%Y%m%d%H%M`.backup; 
    else 
        mkdir -p ~/.backup/`dirname $1`; 
        cp $1 ~/.backup/$1-`date +%Y%m%d%H%M`.backup; 
    fi 
}

Bash 查找给定应用程序的可能plist-Files

mdfind 'kMDItemFSName == "*textmate*"cw' | grep "\.plist$"

Bash GOTCHA:bash / sh处理未公开的报价

bourne shells silently insert an unbalanced single, double or back quote at EOF (including here-documents)

Bash 自动添加当前目录中的所有新文件。

#!/bin/bash

if [ ! "$1" ]
then
  1='.'
fi

echo "Processing $1"
svn add $1 `svn st $1 | grep '^?.*' | tr -d '? ' | sort -n | tr '\n' ' '`

Bash 记忆统计

#!/bin/bash
bean=`cat /proc/user_beancounters`
guar=`echo "$bean" | grep vmguar | awk '{ print $4;}'`
priv=`echo "$bean" | grep privvm | awk '{ print $2;}'`
let totl=guar/256
let used=priv/256
let free=$totl-$used
echo "                             "
echo "  #########################  "
echo "  #     Memory  Stats:    #  "
echo "  #########################  "
echo "                             "
echo "     Total......: $totl MB   "
echo "     In Use.....: $used MB   "
echo "     Available..: $free MB   "
echo "  =========================  "
echo "                             "

Bash 批量重命名目录中的文件

for F in * ; do NF=`echo $F | perl -lne "s/ /_/g; s/\._/./g; s/[',-]//g; print lc"` ; mv "$F" "$NF" ; done

Bash 从grep中排除一些目录

find . -name "*.html" \( -name 'dirFoo' -prune -o  -name 'dirBar' -prune \) | xargs grep -n "THE_PATH_YOU_ARE_LOOKING_FOR"

Bash 删除.svn

find . -name "*.svn" -exec rm -f -r {} \;