User Tools

Site Tools


mywiki:language:bash

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

replace_string_file.sh
for f in *
do
    sed 's/string1/string2/g' $f > $f.new &&
    mv $f.new $f
done

wirte multiple line to one file

cat_example.sh
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

dec_hex.sh
a=100 
b=`printf "0x%x", $a`
echo $b

Display softlink as specified

find ./ -type l

find ./ -type l -exec ls -l {} \;<br />find ./ -type l | xargs file

for f in $(find ./ -type l); do if [ -d “$f” ]; then ls -al “$f”; fi; done

for f in $(find ./ -type l); do if [ -f “$f” ]; then ls -al “$f”; fi; done

find ./ -type l | while read f; do if [ ! -e “$f” ]; then ls -l “$f”; fi; done

ln -s xxxx -T /home/yyy/zzz ( link current directoryxxxx to /home/yyy/zzz also changed xxxx to zzz)

ln -s xxxx -t /home/yyy/ ( link current file xxxx to /home/yyy/xxxx)

tree -d

mywiki/language/bash.txt · Last modified: by 127.0.0.1