Common bash script ====== pattern with ls commands -- need further study ====== ls -1FA | grep \/ | sed -e "s/\// /g" -e "/CVS/d" -e "/include/d" -e "/.svn/d" ====== extract mac address ====== method 1: ifconfig eth0 | awk '/HWaddr/ {print $5}' method 2: ifconfig eth0 | grep -o -E '([[:xdigit:]]{1,2}:){5}[[:xdigit:]]{1,2}' Note The -o will cause grep to only print the part of the line that matches the expression. [[:xdigit:]]{1,2} will match 1 or 2 hexidecimal digits (Solaris doesn't output leading zeros). ====== Change string1 to sing2 in all files in current folder ====== for f in * do sed 's/string1/string2/g' $f > $f.new && mv $f.new $f done ====== wirte multiple line to one file ====== cat >/var/test << "EOF" plugin /lib/pppd/2.4.4/pppoatm.so user test password test lcp-echo-interval 10 EOF ====== change Dec value to Hex value ====== a=100 b=`printf "0x%x", $a` echo $b ====== Display softlink as specified ====== === Display all softlink under current folder ==== find ./ -type l === Display all softlink and ls or file ==== find ./ -type l -exec ls -l {} \;
find ./ -type l | xargs file === Display all softlink which link to a directory only === for f in $(find ./ -type l); do if [ -d "$f" ]; then ls -al "$f"; fi; done === Display all softlink which link to a file === for f in $(find ./ -type l); do if [ -f "$f" ]; then ls -al "$f"; fi; done === Display all broken softlink === find ./ -type l | while read f; do if [ ! -e "$f" ]; then ls -l "$f"; fi; done === link a directory to another directory === ln -s xxxx -T /home/yyy/zzz ( link current directoryxxxx to /home/yyy/zzz also changed xxxx to zzz) === link a file to another directory's file === ln -s xxxx -t /home/yyy/ ( link current file xxxx to /home/yyy/xxxx) ==== print directory tree ==== tree -d