Linux frequently used commands

shell terminal

  • !! the previous command (Actually the latest command list with command history)
    !-1 is equal to !!
    !-2 is second command list with command history
    !^ first parameter
    !:1 first parameter
    !:n the n parameter
    !:$ last parameter

  • C-A/E jump to the head/end position
    C-U/K trim to head/tail
    C-P/N prev/next command
    C-R history command
    C-- zoom in
    C-L clear screen, same as clear
    C-C cancel current command
    C-& cancel modify
    C-T switch
    C-Y paste
    C-W delete a word
    Below operation need to unset Enable menu access keys option of terminal.
    C-f/b move cursor forward/backward a character
    M-f/b move cursor forward/backward a word
    C-d delete a character forward
    C-h delete a character backward
    M-d delete a word froward
    C-M-h delete a word backward, the word was splited by any special symbols
    C-w delete a word backward, the word was splited by space symbol only
    C-] search character forward
    C-M-] search character backward

  • <alt>+. get the last parameter of previous command

common command

  • cd - switch to last dir
    cd switch to user home dir

  • cp filename{,.bak} a fast method to bakup a file

  • mv filename{.bak,} a fast method to cut the suffix

  • time command count the elapsed time

  • mount -t cifs -o username=***,passwd=*** //ip/path /mnt/test
    mount network sharing dir
    mount -t iso9660 /mnt/iso/FC17-DVD.iso /mnt/dvd
    use for mounting ISO file
    mount --bind /root/project/myprj /root/x86_64_build/source
    mount a dir to another, use for across-compilation mostly
    mount -t tmpfs -o size=1024m tmpfs /mnt/ram
    mount memory as a w/r dir (use for high speed I/O operation, and disk space not enough)

  • tar xvf example.tar.gz -C /root/test extract files to specific dir
    tar tvf example.tar.gz list the contents of an archive
    tar -zcvf - stuff | openssl des3 -salt -k *** | dd of=stuff.des3 encryption
    tar cvfz chenxu.tar.gz dir --exclude dir/dir1 --exclude dir/dir2/dir3
    tar -xvf 1425279081.tar.gz var/log/message get only one file
    dd if=stuff.des3 | openssl des3 -d -k *** | tar zxf - decryption
    7z a -t7z -ptestpsw123 mytest.7z -r testfolder/* zip folder and encrypt it by 7z

  • getconf LONG_BIT print the operator system bits
    grep -c "lm" /proc/cpuinfo if output is not 0, it is 64bit cpu

  • du -sh
    du -s * |sort -n |tail

  • free bg kill pid killall proc chmod 777 (r:4,w:2,x:1)(user,group,all)

  • find / -name "***"
    find path \( -name "*.h" -or -name "*.c" \) -exec grep -in "***" {} \;
    find ./ -name "*.*" -exec ls -l {} \; |awk '{print $5,$9}' |sort -n |tail find the 10 biggest files.
    find / -type d -name "gedit" search direactorys
    find . \( -path ./.git -o -path dir2 \) -prune -o -type d -print search sub-dir, except .git and dir2
    find /usr/include/ -path /usr/include/boost -prune -o -name '*.h' -print >1.txt
    find . -name ".svn" | xargs rm -rf find .svn folder in current directory, and remove it.
    find ./ \( -name "*.h" -or -name "*.c" \) -exec wc -l {} \; | awk '{s+=$1} END {print s}' count lines of specify files
    find ./ \( -name "*.h" -or -name "*.c" \) | xargs wc -l | tail -n 1 count lines of specify files
    the upon two command can count lines of specify files, but what is the
    difference of them, look this
    Difference xargs and exec
    you will find the answer.
    find ./ -path ./perl -prune -o -name "*.so" -exec cp {} ../net-snmp-5.4.4-sdk/lib/ \;
    copy files which search by find, search exclude ./perl path
    find /usr -size +100M find file size larger than 100M
    find /home -mtime +120
    find /var \! -atime -90
    find <dir> -executable -type f only find executable files

  • grep -r "abc" /root/source
    grep -r --include "*.h" "date" path
    grep -m 1 "model name" /proc/cpuinfo only display the first match line
    grep -i -E "abc|123" match abc or 123, -i ignore, -E extended regular expression.
    grep -r -l "main" . search all files under each directory, -l files-with-match, -L files-withou-match
    grep -w "linux" *.md match word
    grep -rl --include=*.{h,cpp} "socket" . search socket only with .h .cpp files
    grep --exclude-dir="_posts" --exclude-dir="_site" -r "Dennis" ./ exclude specify directory
    grep -rni '[^a-zA-Z]abc[^a-zA-Z]' ./ match like “tt.abc.1234”, not match like “ttabccd”

  • cut -d"" -f1
    e.g:
    [root@localhost ~]# sensors |grep "Core "
    Core 0: +30.0°C (high = +76.0°C, crit = +100.0°C)
    Core 1: +37.0°C (high = +76.0°C, crit = +100.0°C)
    [root@localhost ~]# sensors |grep "Core " |cut -d"+" -f2 |cut -d" " -f1
    30.0°C
    37.0°C

  • history|awk '{print $2}'|awk 'begin {FS="|"} {print $1}'|sort|uniq -c|sort -rn|head -10

  • ps aux | sort -nk +4 | tail
    ps -eo pid,lstart,etime | grep 3208 view the start and running time of specify process.
    ps axjf print process tree
    ps -ef see every process
    ps -eLf get about thread info
    ps -U root -u root u see every process running as root
    pgrep firefox print the procee id of firefox

  • uname -a

  • whereis cp
    rpm -qf /usr/bin/cp
    rpm -ivp ***.rpm

  • rpm -qpl packetname list files
    rpm -i --relocate change install directory
    rpm -qa |grep XXX check whether XXX was installed
    rpm -e $(rpm -qf $(which teamviewer)) remove software

  • mkdir -p /test/dir1/dir2/dir3

  • ftp 192.168.1.102 2121
    pwd view remote directory
    lcd change to the local directory
    !ls list local files
    put 1.jpg
    get 2.jpg
    mput *.jpg
    mget *.jpgdownload multiple files
    bye

  • wget ftp://IP:PORT/* --ftp-user=xxx --ftp-password=xxx -r support download
    multiple files and directories, good to replace ftp

awk and sed

  • awk
    awk FS'' 'condition1{operator1}condition2{operator2}...' filename
    NR:number row, NF:number field
    awk 'NR==1{print $0}'
    arr=($(awk -F'#' '{print $1,$2,$3,$4}' $conf_file))
    ps aux | awk 'NR==1{print $0}$3>10{print $0}'
    awk -F'<|>' '{if(NF>3){print $2 ":" $3}}' /tmp/test.xml parse xml file
    awk -F'=' '/HWADDR/{print $2}' /etc/sysconfig/network-scripts/ifcfg-eth0

  • sed
    sed [options] 'command' file(s)
    sed [options] -f scriptfile file(s)
    sed -i '/'$prj'/{s/\(.*#.*#\)[0-9]\+/\1'$rev_new'/}' $conf_file
    sed -n 10,23p filepath -n print the specific lines
    sed 'N;s/\n/ /' filepath join two line into one
    echo -e "11\n22\n33\n" | sed -n '/22/{n;p}' print next line after match
    sed ':a;N;s/\n/ /;ba;' file join all lines

git and svn

  • git
    git clone url
    git add .
    git commit -m "***"
    git commit file -m "***"
    git push origin master
    git status
    git diff
    git rm *** remove file
    git rm -r *** remove directory
    git pull
    git mv *** ###
    git remote -v show remote repository info
    git reset <file> undo git add
    git checkout HEAD /path/file undo git rm on one file
    git rm $(git ls-files --deleted) undo git rm multiple files

  • svn
    svn list url
    svn co url
    svn status
    svn update
    svn info url
    svn di
    svn di -r ver1:ver2
    svn di -r ver1:ver2 path
    svn revert [-R] path
    svn merge -r ver2:ver1 path
    svn log -r ver1:ver2
    svn log -l5 show 5 latest logs
    svn add path
    svn commit -m "***"
    svn ci path -m "***"
    ls ~/.subversion/auth/svn.simple user information location

network

  • ip addr
    cat /sys/class/net/eth{0,1}/address display mac address
    ip addr add 172.16.60.69/24 dev eth1
  • ifconfig eth0 down; ifconfig eth0 hw ether MAC_ADDR; ifconfig eth0 up change MAC address
    ifconfig eth2 192.168.1.102 netmask 255.255.255.0 up add ip address for eth2
    ifconfig eth2:1 192.168.1.23 netmask 255.255.255.0 up add another ip for eth2
    ifconfig eth0 mtu 6000 set MTU
  • ping -I 192.16.4.23 192.16.4.70 set source address to specified interface address
  • route add default gw 172.16.130.1 eth2
    route del default gw 172.16.130.1 eth2
    route add -host 192.168.168.110 dev eth0
    route del -host 192.168.168.110 dev eth0
    route add -net 172.16.130.0/24 gw 172.16.130.1 eth2
    route del -net 172.16.0.0 netmask 255.255.0.0 dev eth0
    ip route flush cache
  • python -m SimpleHTTPServer
    python -m http.server for windows
  • ssh root@172.168.1.101
  • ssh -f -NC -D7070 user@shell.cjb.net ssh tunnel
    ssh -f -NC -D7070 user@216.194.70.6 ssh tunnel
  • scp abc.sh root@172.168.1.101:/root/test upload file
    scp root@172.168.1.101:/root/test/abc.sh /root/mytest download file
    sshpass -p passwd scp abc.sh root@172.168.1.101:/root/test
  • nmap ip
    nmap 192.168.1.1 -p 8000 check the port is open or not
    nmap -v -sn 192.168.1.1/24
    nmap -v -sn 192.168.1.1/24 |grep 'report' |grep -v 'down' |awk '{print $NF}' scan local alive ip
  • nc -z -w 1 IP PORT
    nc -z -w 1 192.168.1.1 100
    nc -z -w 1 -u 192.168.1.1 100
    nc -z -w 1 192.168.1.100 1-65535 scan all ports from 1 to 65535
  • lsof -i:111
    netstat -apn | grep 111
    iptables -L list rules
    iptables -L INPUT --line-numbers
    iptables -A INPUT -p tcp --dport 111 -j DROP forbid specific port
    iptables -A OUTPUT -p tcp --dport 111 -j DROP
    iptables -A INPUT -p tcp --dport 8024 -j ACCEPT all rule, allow port 8024
    iptables -I INPUT 5 -p tcp --dport 8024 -j ACCEPT add rule to specify position(5)
    iptables -D INPUT -p tcp --dport 8024 -j ACCEPT delete rule
    service iptables save
    service iptables stop
    service iptables start
  • curl ifconfig.me
    curl ipinfo.io/IP_ADDRESS get geographic location of an IP address
  • geoiplookup IP_ADDRESS
  • dig domain dig -x host
  • netstat -nlp view service and listen ports
    netstat -npt view tcp connections
    netstat -s display networking statistics
  • wget url download file
    wget -m -p -np -k -E http://site/path/ mirror the site
    wget -A pdf,jpg -m -p -np -k -E http://site/path/ only download pdf and jpg file
    wget url_file -O new_name.file rename
  • tcpdump -D list available device(run as root)
    tcpdump -i p4p1 host 172.16.130.88 and port 80 -n use specify interface “p4p1”
    tcpdump -i p4p1 host 172.16.130.88 and port 3260 -w tcpdump.pcap
    tcpdump -l | tee dat
    tcpdump -U host 172.16.130.88 and port 3260 -w tcpdump.pcap flush each packet to packet-buffered
    tcpdump host 210.27.48.1 and \ (210.27.48.2 or 210.27.48.3 \)
    tcpdump -i eth0 src host hostname
    tcpdump -i eth0 dst host hostname
    tcpdump -n -e -i eth0 icmp
    tcpdump -n -e icmp
    tcpdump -n -e arp
  • telnet 172.16.50.39 3128 check port is available or not
  • arp -a
  • squid -CNd1
  • traceroute www.baidu.com display all the route from my host to the website

os

  • Fedora
    Alt+Tab switch windows
    Alt+` switch sub-windows
    Win windows key, use to show all application
    Win -> Space , search application
  • yum use local repository
    • mount iso file to /mnt/cdrom
    • modify /etc/yum.repos.d/CentOS-Media.repo, add text “file:///mnt/cdrom/“
      [c6-media]
      name=CentOS-$releasever - Media
      baseurl=file:///media/CentOS/
      file:///media/cdrom/  
      file:///media/cdrecorder/  
      file:///mnt/cdrom/  
      
      gdgcheck=1
      enabled=1
      gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6
  • yum install XXX -y
    yum search XXX
    yum remove XXX
    yum clean all
    yum makecache
  • Ubuntu
    reset root password, press ‘e’ to edit grub boot option, change ‘ro quiet splash’
    to ‘rw init=/bin/bash’, then login terminal with root, use ‘passwd’ to reset.
  • Ubuntu remove software
    • dpkg –get-selections | grep ‘software-name’
    • sudo apt-get remove –purge software_name
    • dpkg -l |grep ^rc|awk ‘{print $2}’ |sudo xargs dpkg -P

vimperator(Firfox plugin)

  • vimperator
    :help Open help page
    :helpall Show all help on one page
    C-[ cancel command mode
    d close current page
    u undo close current page
    / search
    H Go back in the browser history
    gg Go to the top of the page
    G Go to the bottom of the page
    C-f forward page
    C-b backward page
    y Copy the current URL to clipboad
    p Open the URL from current clipboad contents in current buffer
    P Open the URL from current clipboad contents in a new tab buffer
    r Reload current page
    ZZ Quit and save the session
    C-n Go to the next buffer
    C-p Go to the previous buffer
    gi Go to input field
    g-u Go to the parent directory
    g-U Go to the root of the website
    c Start caret mode.Like normal mode of vim, use h j k l to move, and
    press v to start visual mode, then press y to copy select text
    gi Use [count]gi to Focus to the [count]th input field
    C-l Go to URL editor and select it
    C-t Open a new tab

program

  • man 2 sys_call_name view system call function description
    man 2 open, man 2 read, man 2 write, man 2 fork
    man 3 errno view error number description
    man 3 printf
    man ascii

Others

  • vimdiff a.log b.log diff two files
    vim -b file edit binary file, use :%!xxd and :%!xxd -r
  • diff /tmp/test01 /tmp/test02 compare file in two directory
    diff -r /tmp/test01 /tmp/test02 compare file in directory and subdirectory
    diff /tmp/test01/1.c /tmp/test02/2.c compare two files
  • patch
    diff a.c b.c > c.patch
    patch a.c c.patch
  • vmstat iostat ifstat nload top hexdump od
    hexdump -C filename display hex+ASCII of file
    iostat -x 2 5
    ipcs show all ipc info
    nload monitor network traffic, use tab key to switch to next interface, and q to quit.
  • dd if=/dev/zero of=$test_file bs=1M count=$dev_size 2>> $log
    dd of=/dev/sdh of=/dev/zero bs=1M count=500 oflag=direct test the real hard disk speed
    dd if=path/Fedora-os.iso of=/dev/sdb install fedora live os to U disk(make
    sure the mount directory of U disk is /dev/sdb, if not should change the out file directory)
  • > file.txt
  • watch -n 5 command
  • chroot .
  • date "+%F %R:%S"
    date "+%y%m%d%H%M%S"
    date +%s print timestamp of current time
    date -d @1420210697 translate timestamp to datetime
    date +%s -d"Jan 1, 1970 00:00:01" translate datetime to timestamp
  • which executefile print directory of executefile
    ldd /usr/bin/executefile print shared library dependencies
    nm /usr/lib64/libXXX.so print interface
  • cat /proc/uptime | awk -F. '{d=($1/86400);h=($1%86400)/3600;m=($1%3600)/60;s=($1%60);printf("system had run %d day %d hours %d mins %d secs\n",d,h,m,s)}'
  • fuser -u /home
    fuser -v -n tcp 7070
  • echo 1 > /proc/sys/kernel/sysrq enable sysrq
    echo "b" > /proc/sysrq-trigger reboot
    echo "o" > /proc/sysrq-trigger shutdown
    shutdown -h now shutdown
    shutdown -h +10 shutdown 10 minutes later
    shutdown -h 10:00 shutdown at ten clock
  • dmidecode | more : view mainboard info
    cat /proc/cpuinfo : view CPU info
    cat /proc/pci : view pci info
    lspci : view PCI info
    cat /proc/meminfo : view memory info
    fdisk -l : view disk info
    df : view disk space useage
    cat /proc/interrupts: view interrupt request
    dmesg | more : view device debug message
  • pdftk *.pdf cat output onelargepdfile.pdf merge pdf to one
    pdftk test.pdf cat 1-3 6-20 22-end output net.pdf cut page 4,5,21 from file
    qpdf --password=1234 --decrypt encrypted.pdf decrypted.pdf decrypt pdf file
    qpdf --decrypt encrypted.pdf decrypted.pdf for empty password
  • vi -e -s -c ":%s/pattern/string/g" -c ":wq" file execute vi comand in shell
  • format u disk
    fdisk -l : find u disk
    umount /dev/sdb1 : umount u disk
    mkfs.vfat /dev/sdb1 : format as fat
  • history -c clean
    history -d offset delete specify command
  • convert -resize 1024x768 input.svg output.png convert svg to png
    convert file.pdf file.png convert pdf to images(file-XX.png)
    convert *.png file.pdf convert images to one pdf
    convert -fill green -pointsize 40 -draw 'text 10,50 "funny day"' foo.png comment.png add text to picture
  • import foo.png capture a select rectangular
  • for i inls; do mv -f $iecho $i | sed ‘s/^………/iscsi/‘; done rename
    files, replace the first 5 characters with iscsi
  • fc-list list fonts
  • strace -o 1.log -s 1024 -T -tt -p 1234 print the system call and time used for process 1234
  • printf format and print data
    printf '%x\n' 1550 convert octal value 1550 to hex, output 60e
    printf '%d\n' 0x99 convert hex value 0x99 to octal, output 153
  • echo "51200000/64/3“ |bc -l calculate
  • echo 'abc 123dd 3xxx tt' |tr -s '[:space:]' '\n' translate spaces to be line break symbol
    echo 'abc 123dT 3xXX tt' |tr '[:upper:]' '[:lower:]'
    cat test.md |tr -s '[:space:]' '\n' |tr '[:upper:]' '[:lower:]' |sort |uniq -c| sort -nr |head -10
    find the top hot words for text document.
  • zip -Phq.hzy.zf.xf.hx.l@123 test.zip test zip “test” file to be test.zip using password
    unzip -Phq.hzy.zf.xf.hx.l@123 test.zip unzip zip file with password
    unzip -Z test.zip unzip file without password
    cat abc.zip.00* >abc.zip merge zip files
  • pkill -9 -t pts/1
  • setenforce 0 forbid Selinux temporary
    sed -i 's/SELINUX=.*/SELINUX=disabled/g' /etc/selinux/config forbid Selinux, need reboot
  • kill PID
    kill -9 PID
    kill -kill PID
  • vgchange -ay
  • lsof |grep '/core/messages' find which application open the specify file
  • for x inseq 1 1 10; do ps -eo state,pid,cmd | grep "^D"; echo "----"; sleep 5; done
    print the processes in a “D” state every 5 seconds for 10 intervals
  • echo export LANG=en_US.utf8 >>~/.profile, set lang for os, and checking with echo $LANG or locale
  • gstack threadID
  • rm !(*.pdf) remove files except pdf
  • [! -d /temp/test] && mkdir /tmp/test if folder not exist, create it.

Reference

Copy file with progress bar

Copy file with progress bar

#!/usr/bin/bash

print_bar() {        # print the bar 

    local Count=$1
    local Max=$2
    local Remain=$3
    local Elapsed=$4
    local Speed=$5
    local LenBar=50
    if [ $# -eq 6 ]; then
        LenBar=$6
    fi
    if [ ${Count} -gt ${Max} ]; then
        Count=${Max}
    fi
    local Percent=$(((100*Count)/Max))
    local BarPercent=$(((LenBar*Percent)/100))

    if [ ${Percent} -eq 100 ]; then
        Remain=0
    fi

    local BarProgress=$(for i in $(seq ${BarPercent}); do echo -n '='; done)
    BarProgress="${BarProgress:0:${#BarProgress}}>"
    local Nxt=$((LenBar-BarPercent))
    local BarPad=$(for i in $(seq ${Nxt}); do echo -n '.'; done)

    local TElapsed=$(date -u -d @$Elapsed +%Hh%Mm%Ss)
    TElapsed=$(echo ${TElapsed} | sed -e "s/^00h//" -e "s/^00m//")

    local TRemain=$(date -u -d @$Remain +%Hh%Mm%Ss)
    TRemain=$(echo ${TRemain} | sed -e "s/^00h//" -e "s/^00m//")

    local larg=$(tput cols)
    if [ ${TimeElapsed} -gt ${TimeDiff} ] && [ ${EndBar} -eq 0 ] && [ ${Remain} -gt 0 ]; then        
        local mess0="[ ${Percent}% ][${BarProgress}${BarPad}] (${Speed}K/s) [ Remain: ${TRemain} Spent: ${TElapsed} ]"
        local mess=" :: ${mess0}"
        local mess1="${TAB_}${mess0}"
        echo -en "\r${mess1}\033[K"
        if [ ${#mess} -gt ${larg} ]; then
            echo -ne "\r\033[1A" src/lib/progbar
        fi
    else
        echo -en "\r${TAB_}[ ${Percent}% ][${BarProgress}${BarPad}][ Time: ${TElapsed} ]\033[K"
    fi
}

if [ $# -eq 2 ]; then
    cp $1 $2 &
fi

file_size_org=0
file_size_dst=0
file_size_org=$(du $1 | awk '{print $1}')
#echo org size ${file_size_org}

TimeDiff=10
EndBar=1
TimeStart=$(date +%s)
while [ ${file_size_org} -gt ${file_size_dst} ] && sleep 1
do
    file_size_dst=$(du $2 | awk '{print $1}')
    TimeNow=$(date +%s)
    TimeElapsed=$(( TimeNow-TimeStart ))
    Speed=$(( file_size_dst/TimeElapsed ))
    TimeRemain=$(( (file_size_org-file_size_dst)/Speed ))
#    echo dst size ${file_size_dst}
    print_bar ${file_size_dst} ${file_size_org} ${TimeRemain} ${TimeElapsed} ${Speed}
#    print_bar ${BytesLoadNow} ${BytesLoadMax} ${TimeRemain} ${TimeElapsed} ${Speed} ${LenBar}
done
echo

Reference

SVN project revision monitor on Linux

Monitor revision of SVN repository, auto send change log to user by mail

pmt.sh

#!/usr/bin/bash
################################################################################
# 自动获取SVN版更新信息,并发送邮件通知
# 历史记录:
#   2012-12-20    v1.0    Dennis  Create
#   2012-12-21    v1.1    Dennis  增加注释,加入文件存在判断和写日志
#   2012-12-24    v1.2    Dennis  增加log日期注释,加入文件存在判断和写日志
################################################################################

conf_file=/etc/pmt.conf
log_file=/tmp/pmt.log

cur_time=`date "+%F %R:%S"`
echo $cur_time "pmt start" >> $log_file

# 如果配置文件不存在, 退出程序
if [ ! -f $conf_file ]
then
    echo "Not found $conf_file" >> $log_file
    goto _EXIT
fi

# Fields: project#url#revision#mail
# 每行列数目为4,使用#号作为分割符号提取行信息到数组arr 
field_size=4
arr=($(awk -F'#' '{print $1,$2,$3,$4}' $conf_file))

# 以4个元素为一个单位,获取数组大小, 以模仿二维数组
item_size=$[${#arr[@]}/$field_size]

while true 
do
    # 循环二维数组(模仿)
    for ((i=0;i<$item_size;i++))
    do
    {
    index=$[i*$field_size]

    prj=${arr[$[index+0]]}
    url=${arr[$[index+1]]}
    rev_old=${arr[$[index+2]]}
    # 提取最新版本号
    rev_new=$(svn info $url | awk 'NR==8{print $NF}')

    if (( $rev_new > $rev_old ))
    then
        # 更新版本号到数组
        arr[$[index+2]]=$rev_new

        # 提取log信息
        svn log $url -r $rev_new:$rev_old > svn.log

        subject="[svn monitor]"${arr[$[index+0]]}" update"
        to=${arr[$[index+3]]}

        # 发送邮件通知
        mail -s "$subject" $to < svn.log

        # 修改为最新版本号
        # sed中使用变量要加上单引号
        sed -i '/'$prj'/{s/\(.*#.*#\)[0-9]\+/\1'$rev_new'/}' $conf_file

        cur_time=`date "+%F %R:%S"`
        echo $cur_time "${arr[$[index+0]]} update, mail to $to" >> $log_file
    fi
    }
    done
    sleep 5
done

:_EXIT
cur_time=`date "+%F %R:%S"`
echo $cur_time "pmt exit" >> $log_file
exit 0

pmt.conf

project01#http://172.168.1.122/repos/dev/project01#18559#usr01@gmail.com
project02#http://172.168.1.122/repos/dev/project02#18635#usr02@gmail.com

Viusal studio project auto compile

Windows Requirements

microsoft visual studio 2005 or newer
subversion 1.7.7 or newer

add the path of command tool "svn" and "devenv" to environment path

check out project by svn

svn co project_svn_url output_path -r revision

svn_co.bat

@ECHO off&SETlocal enabledelayedexpansion 

REM Useage: svn_co.bat svn_src_url out_path revision log_file

SET func="check out project"

SET src_url=%1
SET out_path=%2
SET src_rev=%3
SET log_file=%4
SET parameters=%src_url%

IF NOT "%out_path%"=="" SET parameters=!parameters! %out_path%

IF NOT "%src_rev%"=="" SET parameters=!parameters! -r %src_rev%

SET log_file_tmp=NUL
IF NOT "%log_file%"=="" SET log_file_tmp=%log_file%

svn co !parameters!

SET /a ret_code=%ERRORLEVEL%
IF %ret_code% EQU 0 (
    @ECHO svn checkout success
) ELSE (
    @ECHO svn checkout fail
)

use devenv for compile

devenv solution_file /build "release|win32"

compile.bat

@ECHO off

REM Useage: compile.bat solution_file

SET sln_file=%1
SET cfg_build="Release|Win32"

devenv %sln_file% /build %cfg_build%

SET /A retval=%ERRORLEVEL%
EXIT /B %retval%

hardware monitor

Most of the motherboard can monitor hardware right now, what they can support is
depends on the sensor used. So, if you want to known how monitor, you should
get the type of sensor chip. I know supermicro x9scl use Nuvoton NCT6776F and
X8SIL use Winbond W83627DHG-P. Once get this message, you can search the
datasheet, and get the method how to do it.

On different operation system, have different method to read/write I/O port. I
know WinIO on windows, IoWrite8/16/32 on Linux.

There is a good open source software “Open Hardware Monitor”, which develop by
C# language. It support almost all the motherboard.


1. Datasheet of chips

Look the access channels on file NCT6776F_NCT6776D_Datasheet_V1_2
page 275

19.2 ACCESS CHANNELS
There are two different channels to set up/access the GPIO ports. The first one is the indirect access via register
2E/2F (4E/4F, it depends by HEFRAS trapping). The registers can be read / written only when the respective
logical device ID and port number are selected.

known that rigister index is 0x2E, and data Input/Output port is 0x2F

On page 54
To program the NCT6776F / NCT6776D configuration registers, the following configuration procedures must be
followed in sequence:
(1). Enter the Extended Function Mode.
(2). Configure the configuration registers.
(3). Exit the Extended Function Mode.

7.1.1 Enter the Extended Function Mode
To place the chip into the Extended Function Mode, two successive writes of 0x87 must be applied to Extended
Function Enable Registers (EFERs, i.e. 2Eh or 4Eh).

7.1.2 Configure the Configuration Registers
The chip selects the Logical Device and activates the desired Logical Devices through Extended Function Index
Register (EFIR) and Extended Function Data Register (EFDR). The EFIR is located at the same address as the
EFER, and the EFDR is located at address (EFIR+1).
First, write the Logical Device Number (i.e. 0x07) to the EFIR and then write the number of the desired Logical
Device to the EFDR. If accessing the Chip (Global) Control Registers, this step is not required.

Secondly, write the address of the desired configuration register within the Logical Device to the EFIR and then
write (or read) the desired configuration register through the EFDR.

7.1.3 Exit the Extended Function Mode
To exit the Extended Function Mode, writing 0xAA to the EFER is required. Once the chip exits the Extended
Function Mode, it is in the normal running mode and is ready to enter the configuration mode.

Software Programming Example
The following example is written in Intel 8086 assembly language. It assumes that the EFER is located at 2Eh, so
the EFIR is located at 2Eh and the EFDR is located at 2Fh. If the HEFRAS (CR[26h] bit 6 showing the value of
the strap pin at power on) is set, 2Eh can be directly replaced by 4Eh and 2Fh replaced by 4Fh.
This example programs the configuration register F0h (clock source) of logical device 1 (UART A) to the value of
3Ch (24MHz). First, one must enter the Extended Function Mode, then setting the Logical Device Number (Index
07h) to 01h. Then program index F0h to 3Ch. Finally, exit the Extended Function Mode.

;-----------------------------------------------------
; Enter the Extended Function Mode
;-----------------------------------------------------
MOV DX, 2EH
MOV AL, 87H
OUT DX, AL
OUT DX, AL
;-----------------------------------------------------------------------------
; Configure Logical Device 1, Configuration Register CRF0
;-----------------------------------------------------------------------------
MOV DX, 2EH
MOV AL, 07H
OUT DX, AL
; point to Logical Device Number Reg.
MOV DX, 2FH
MOV AL, 01H
OUT DX, AL
; select Logical Device 1
;
MOV DX, 2EH
MOV AL, F0H
OUT DX, AL
; select CRF0
MOV DX, 2FH
MOV AL, 3CH
OUT DX, AL
; update CRF0 with value 3CH
;-----------------------------------------------
; Exit the Extended Function Mode
;----------------------------------------------
MOV DX, 2EH
MOV AL, AAH
OUT DX, AL

2. Open Hardware Monitor

Homepage
source code

The Open Hardware Monitor is a free open source software that monitors
temperature sensors, fan speeds, voltages, load and clock speeds of a computer.

As below, introduct how to use VC++ to monitor HW status on windows:

1). modify computer.cs,add some interface like GetFanSpeed(). if have problem , look report function .
2). set the project properity to output class library.
3). Reference VC++ use C# DLL

1.1 Analyze open-hardware-monitor

Use Winbond W83627DHG-P chip as example.

A description about how to monitor hardware, see this
http://www.supermicro.com/support/faqs/faq.cfm?faq=12015

Question
  I'm trying to access the Winbond 83627DHG-P IO chip on the motherboard X8SIL. 
  We want to use the LMsensor. Do you have the offset codes for the smbus?

Answer
  Bus Type = ISAIO/SMBus
  One W83627DHG-P

  Windbond W83627DHG-P, Slave Address=0x2d (0x5a in 8-Bit format)
  OR IndexReg=A15, DataReg=A16
  =============================================================

  Fan1 Fan Speed, Bank 0, Offset 0x29 RPM = 1350000/8/Data
  Fan2 Fan Speed, Bank 5, Offset 0x53 RPM = 1350000/8/Data
  Fan3 Fan Speed, Bank 0, Offset 0x28 RPM = 1350000/8/Data
  Fan4 Fan Speed, Bank 0, Offset 0x3f RPM = 1350000/8/Data
  Fan5 Fan Speed, Bank 0, Offset 0x2a RPM = 1350000/8/Data

  CPU Voltage, Bank 0, Offset 0x20 Voltage = Data* 0.008
  -12V Voltage, Bank 0, Offset 0x26 Voltage = ((Data*0.008-2.048)/(10./242.))+2.048
  +12V Voltage, Bank 0, Offset 0x21 Voltage = Data* 0.008/ (10./66.2)

  AVCC Voltage, Bank 0, Offset 0x22 Voltage = Data* 0.016
  3.3Vcc Voltage, Bank 0, Offset 0x23 Voltage = Data* 0.016

  DIMM Voltage, Bank 0, Offset 0x24 Voltage = Data* 0.008
  +5V Voltage, Bank 0, Offset 0x25 Voltage = Data* 0.008/ (10./40.)
  +3.3VSb Voltage, Bank 5, Offset 0x50 Voltage = Data* 0.016

  VBAT Voltage, Bank 5, Offset 0x51 Voltage = Data* 0.016

  CPU Temperature, Bank 1, Offset 0x50 Temperature = Data

  System Temperature, Bank 2, Offset 0x50 Temperature = Data

  Chassis Intrusion, Bank 0, Offset 0x42, BitMask 0x10 1 = Bad, 0 = Good
  (Clear Bit: Bank 0, Offset 0x46, BitMask 0x80)

  Power Supply Failure, GP23(From W83627DHG-P) 1 = Good, 0 = Bad

1.1.1 File: Hardware/LPC/LPCIO.cs

IO Ports

// I/O Ports
private readonly ushort[] REGISTER_PORTS = new ushort[] { 0x2E, 0x4E };
private readonly ushort[] VALUE_PORTS = new ushort[] { 0x2F, 0x4F };

Winbond, Nuvoton, Fintek

private const byte FINTEK_VENDOR_ID_REGISTER = 0x23;
private const ushort FINTEK_VENDOR_ID = 0x1934;

private const byte WINBOND_NUVOTON_HARDWARE_MONITOR_LDN = 0x0B;

private const byte F71858_HARDWARE_MONITOR_LDN = 0x02;
private const byte FINTEK_HARDWARE_MONITOR_LDN = 0x04;

private void WinbondNuvotonFintekEnter() {
  Ring0.WriteIoPort(registerPort, 0x87);
  Ring0.WriteIoPort(registerPort, 0x87);
}

private void WinbondNuvotonFintekExit() {
  Ring0.WriteIoPort(registerPort, 0xAA);
}

ITE

private const byte IT87_ENVIRONMENT_CONTROLLER_LDN = 0x04;
private const byte IT8705_GPIO_LDN = 0x05;
private const byte IT87XX_GPIO_LDN = 0x07;
private const byte IT87_CHIP_VERSION_REGISTER = 0x22;

private void IT87Enter() {
  Ring0.WriteIoPort(registerPort, 0x87);
  Ring0.WriteIoPort(registerPort, 0x01);
  Ring0.WriteIoPort(registerPort, 0x55);
  Ring0.WriteIoPort(registerPort, 0x55);
}

private void IT87Exit() {
  Ring0.WriteIoPort(registerPort, CONFIGURATION_CONTROL_REGISTER);
  Ring0.WriteIoPort(valuePort, 0x02);
}

SMSC

private void SMSCEnter() {
  Ring0.WriteIoPort(registerPort, 0x55);
}

private void SMSCExit() {
  Ring0.WriteIoPort(registerPort, 0xAA);
}

How to get value:

call ReadByte to get value:

byte id = ReadByte(CHIP_ID_REGISTER);
byte revision = ReadByte(CHIP_REVISION_REGISTER);

look at function ReadByte:

private byte ReadByte(byte register) {
  Ring0.WriteIoPort(registerPort, register);
  return Ring0.ReadIoPort(valuePort);
}

first, write register value to registerPort;
second, read value from valueport.


1.1.2 File: Hardware/LPC/W836XX.cs

How to get value:

// Hardware Monitor
private const byte ADDRESS_REGISTER_OFFSET = 0x05;
private const byte DATA_REGISTER_OFFSET = 0x06;

// Hardware Monitor Registers
private const byte BANK_SELECT_REGISTER = 0x4E;

private byte ReadByte(byte bank, byte register) {
  Ring0.WriteIoPort(
     (ushort)(address + ADDRESS_REGISTER_OFFSET), BANK_SELECT_REGISTER);
  Ring0.WriteIoPort(
     (ushort)(address + DATA_REGISTER_OFFSET), bank);
  Ring0.WriteIoPort(
     (ushort)(address + ADDRESS_REGISTER_OFFSET), register);
  return Ring0.ReadIoPort(
    (ushort)(address + DATA_REGISTER_OFFSET));
} 

What is the value of “address”:

set value by construction

public W836XX(Chip chip, byte revision, ushort address) {
  this.address = address;
  this.revision = revision;
  this.chip = chip;
  ...
}

on LPCIO.cs, found the calling code:

private const byte BASE_ADDRESS_REGISTER = 0x60;

ushort address = ReadWord(BASE_ADDRESS_REGISTER);

switch (chip) {
  case Chip.W83627DHG:
  case Chip.W83627DHGP:
  case Chip.W83627EHF:
  case Chip.W83627HF:
  case Chip.W83627THF:
  case Chip.W83667HG:
  case Chip.W83667HGB:
  case Chip.W83687THF:
    superIOs.Add(new W836XX(chip, revision, address));
    break;
  ...
}

Get temperature:

private readonly byte[] TEMPERATURE_REG = new byte[] { 0x50, 0x50, 0x27 };
private readonly byte[] TEMPERATURE_BANK = new byte[] { 1, 2, 0 };

for (int i = 0; i < temperatures.Length; i++) {
  int value = ((sbyte)ReadByte(TEMPERATURE_BANK[i], 
    TEMPERATURE_REG[i])) << 1;
  if (TEMPERATURE_BANK[i] > 0) 
    value |= ReadByte(TEMPERATURE_BANK[i],
      (byte)(TEMPERATURE_REG[i] + 1)) >> 7;

  float temperature = value / 2.0f;
  if (temperature <= 125 && temperature >= -55 && !peciTemperature[i]) {
    temperatures[i] = temperature;
  } else {
    temperatures[i] = null;
  }
}

Get fan speed:

call ReadByte(FAN_TACHO_BANK[i], FAN_TACHO_REG[i]) to get speed value to “count”
, then set real fan spee to array variable “fans[]“.

private readonly byte[] FAN_TACHO_REG = 
  new byte[] { 0x28, 0x29, 0x2A, 0x3F, 0x53 };
private readonly byte[] FAN_TACHO_BANK = 
  new byte[] { 0, 0, 0, 0, 5 };       
private readonly byte[] FAN_BIT_REG =
  new byte[] { 0x47, 0x4B, 0x4C, 0x59, 0x5D };
private readonly byte[] FAN_DIV_BIT0 = new byte[] { 36, 38, 30, 8, 10 };
private readonly byte[] FAN_DIV_BIT1 = new byte[] { 37, 39, 31, 9, 11 };
private readonly byte[] FAN_DIV_BIT2 = new byte[] { 5, 6, 7, 23, 15 };


ulong bits = 0;
for (int i = 0; i < FAN_BIT_REG.Length; i++)
    bits = (bits << 8) | ReadByte(0, FAN_BIT_REG[i]);

ulong newBits = bits;
for (int i = 0; i < fans.Length; i++) {
    int count = ReadByte(FAN_TACHO_BANK[i], FAN_TACHO_REG[i]);

    // assemble fan divisor
    int divisorBits = (int)(
            (((bits >> FAN_DIV_BIT2[i]) & 1) << 2) |
            (((bits >> FAN_DIV_BIT1[i]) & 1) << 1) |
            ((bits >> FAN_DIV_BIT0[i]) & 1));
    int divisor = 1 << divisorBits;

    float value = (count < 0xff) ? 1.35e6f / (count * divisor) : 0;
    fans[i] = value;

    // update fan divisor
    if (count > 192 && divisorBits < 7) 
        divisorBits++;
    if (count < 96 && divisorBits > 0)
        divisorBits--;

    newBits = SetBit(newBits, FAN_DIV_BIT2[i], (divisorBits >> 2) & 1);
    newBits = SetBit(newBits, FAN_DIV_BIT1[i], (divisorBits >> 1) & 1);
    newBits = SetBit(newBits, FAN_DIV_BIT0[i], divisorBits & 1);
}

3. lm-sensors

Introduction

lm-sensors configurations

Install

install: yum install lm_sensors
monitor: sensors


4. Use WinIO

watchdog

reset Watchdog timeout

Assembly code:

mov    dx, 2eh
mov    al, 87h
out    dx, al
out    dx, al    ; write 0x87 to port 0x2e twice
mov    al, 07h
out    dx, al    ; set Register 0x07 to Index Port
mov    dx, 2fh
mov    al, 08h
out    dx, al    ; switch to Watchdog control page

mov    dx, 2eh
mov    al, f6h
out    dx, al    ; set Register 0xf6 to Index Port
mov    dx, 2fh
mov    al, ah
out    dx, al    ; write time-out value 0x0A to Data Port

mov    dx, 2eh
mov    al, aah
out    dx, al    ; write 0xaa to port 0x2e once

C code:

IoWrite8(0x2E,0x87); //write 0x87 to port 0x2e twice
IoWrite8(0x2E,0x87);
IoWrite8(0x2E,0x07); //set Register 0x07 to Index Port
IoWrite8(0x2F,0x08); //switch to Watchdog control page

IoWrite8(0x2E,0xF6); //set Register 0xf6 to Index Port
IoWrite8(0x2F,0x0A); //write time-out value 0x0A to Data Port

IoWrite8(0x2E,0xAA); //write 0xaa to port 0x2e once

Want more, visit my windows watchdog project here

WinIO sample


5. Reference:

SVN project revision monitor

Monitor revision change of SVN repository

pmt.bat

@echo off
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: 功能: 监控SVN版本库项目,发现更新自动发送邮件通知 
:: 工具: 
::            subversion    www.sourceforge.net/projects/win32svn
::            blat        www.blat.net
:: 历史:
::        v1.00    2012-12-12    Dennis    create project
::        v1.01    2012-12-13    Dennis    修改邮件附件发送为文本内容发送 
::                                    增加自动更新配置文件中的版本号 
::        v1.02    2012-12-14    Dennis    增加单件实现
::
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
setlocal enabledelayedexpansion

::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: run as a singleton
set "app_title=pmt"
tasklist /v | find "%app_title%">nul && goto _EXIT
title %app_title%

:: 切换到批处理文件所在目录 
cd /d %~dp0

set app_log=pmt.log
set log_file=svnlog.txt
set cfg_path=%cd%\conf
set cfg_file=%cfg_path%\*.conf
echo %date% %time% start application >> %app_log%

set /a prj_index=1
for /f "tokens=* delims=" %%i in ('dir /s /b /a-d "%cfg_file%"') do (
    echo call :_CONF_INFO "%%i" !prj_index! >> %app_log%
    call :_CONF_INFO "%%i" !prj_index!
    set prj_!prj_index!_file="%%i"
    set /a prj_index+=1
)

set /a prj_count=!prj_index!-1
echo Monitor %prj_count% project >> %app_log%
set /a last_rev=0

set "pmt_mail=example@gmail.com"
set "f=-f %pmt_mail%"
set "c=-charset GBK"
:_CHK_REV
:: Check svn revision
:: Send mail by blat when there exist new revision in svn repository
for /l %%i in (1,1,%prj_count%) do (
    echo call :_SVN_LAST_REV !prj_%%i_url! last_rev >> %app_log%
    call :_SVN_LAST_REV !prj_%%i_url! last_rev
    if !last_rev! GTR !prj_%%i_rev! (
        echo !prj_%%i_url! !last_rev! ^> !prj_%%i_rev!
        set /a prj_%%i_rev+=1
        echo project: !prj_%%i_name! > %log_file%
        echo url    : !prj_%%i_url! >> %log_file%
        svn log !prj_%%i_url! -r !last_rev!:!prj_%%i_rev! >> %log_file%

        echo send mail to !prj_%%i_mail! >> %app_log%

        set "s=-s "[svn monitor] !prj_%%i_name! update""
        set "t=-t !prj_%%i_mail!"
        blat %log_file% !s! %f% !t! %c%
        set prj_%%i_rev=!last_rev!

        :: 更新配置文件版本号 
        :: sed的组括号为批处理特殊字符,需使用^转义 
        :: 如果不转义, 可以采用call的方式 
        :: call :_UPDATE_REV !prj_%%i_file! !last_rev!
        sed -i '/rev=/{s/\^(rev=\^)[0-9]\+/\1!last_rev!/}' !prj_%%i_file!
    )
)
:: sleep 5 seconds
ping -n 5 127.1 > nul    
goto :_CHK_REV

::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
::exit
:_EXIT
pause
exit /b 0


::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
::Function

:_CONF_INFO <config file> <project index>
:: Get configure info
:: usebackq 用以解决文件路径中包含空格的情况 
FOR /F "usebackq tokens=1,2* delims==" %%i in (%1) do (
    set "prj_%2_%%i=%%j"
)
GOTO :EOF

:_SVN_LAST_REV <url> [retvar]
:: Get lastest revision
for /f "skip=7 delims=: tokens=2" %%i in ('svn info %1') do (
    (if %2. neq . (set/a%2=%%i)else echo %%i)&goto :eof
)
GOTO :EOF

REM :_UPDATE_REV <file> <revision>
REM :: Update revision
REM sed -i '/rev=/{s/\(rev=\)[0-9]\+/\1%2/}' %1
REM GOTO :EOF

example.conf

name=example_project
url=http://172.168.1.122/repos/dev/example_project/trunk
rev=15793
mail=user@gmail.com,abc@yahoo.com,test@hotmail.com

Send mail use blat

What is blat?

Blat is a Windows (32 & 64 bit) command line utility that sends eMail using SMTP or post to usenet using NNTP.

Home: www.blat.net
syntax: www.blat.net/syntax/syntax.html
ref: how to send emails using blat

Installation

blat -installSMTP smtp.gmail.com abc@gmail.com -u username -pw yourpasswd

Send mail

blat -s "blat mail" -to test@gmail.com -f abc@gmail.com -body"test body"

Send email with body from a file

blat test.txt -s "blat mail" -to test@gmail.com -f abc@gmail.com

specify charset of body file

blat utf8.txt -s "blat mail" -to test@gmail.com -f abc@gmail.com -charset GBK

Send attachment

blat -s "blat mail" -to test@gmail.com -f abc@gmail.com -body"test attach" -attach 1.txt

Visual studio project clean

Clean visual studio project

@ECHO off
setlocal enabledelayedexpansion
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: Clean Visual studio project
:: Dennis
:: 2012-12-14
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

:_LOOP
cls
set "prj_path="
set /p prj_path=Drag project folder here:
if !prj_path!. EQU . goto _EXIT
cd !prj_path!

del *.suo Thumbs.db /f /s /a:h 2>nul
del *.ncb *.user /f /s 2>nul

set /a del_type=1
set /p del_type=Option 1 delete files,2 remove folder(default 1):
if %del_type% GEQ 1 (
    if %del_type% LEQ 2 goto _DEL_TYPE_%del_type%
)
echo Please check your choise, only 1 and 2 is available.
pause
goto _LOOP

:_DEL_TYPE_1
del *.aps *.plg *.bsc *.hpj *.clw *.map *.exp *.cbp *.mdp *.ilk /f /s 2>nul
del *.sbr *.res *.obj *.pch *.pdb *.idb *.tmp *.opt mt.dep /f /s 2>nul
del *.manifest BuildLog.htm /f /s 2>nul
pause
goto _LOOP

:_DEL_TYPE_2
::使用*号做分隔符,解决路径中出现空格导致无法获取完整路径问题 
@for /f "delims=*" %%i in ('dir /s /b /ad') do (
    if /i "%%~ni"=="debug" rmdir /s /q "%%i"
    if /i "%%~ni"=="release" rmdir /s /q "%%i"
)

pause
goto _LOOP

:_EXIT
pause&exit /B 0

Batch skill

Batch skills

1.获取当前日期时间
set datetime=%date:~,10%%time:~,2%%time:~3,2%%time:~6,2%

2.获取当前路径
set pwd=%CD%

3.延时

`ping -n 11 127.0.0.1 >nul`  

ping 本机 11 次,可用于批处理延时 10 秒。命令中的>nul 为屏蔽输出。  
_简短式可以写成:_  
`ping -n 11 127.1 >nul`

4.计算运行时间

    @ECHO off&setlocal enabledelayedexpansion
    CALL :TIME_START
    REM 修改这里的 ping 为你需要写的代码
    ping 127.1 -n 2 >nul
    CALL :TIME_END
    PAUSE&exit /B 0
    :TIME_START
    SET /a time_s=%time:~6,2%
    SET /a time_m=%time:~3,2%
    @ECHO Start  time: %time%
    GOTO :EOF
    :TIME_END
    @ECHO End  time: %time%
    SET /a diff_m=%time:~3,2%-%time_m%
    SET /a diff_s=%time:~6,2%-%time_s%
    SET /a total="%diff_m%"*60+"%diff_s%"
    @ECHO Elapsed time: %total% sec
    GOTO :EOF

_运行效果:_  

    D:\work\project\tmp>test.bat
    Start  time: 13:52:00.43
    End  time: 13:52:01.48
    Elapsed time: 1 sec
    请按任意键继续. . .

5.罗列当前目录所有 txt 文件

@echo off
for %%i in (*.txt) do echo "%%i"
pause

6.罗列当前和子目录所有 cfg 文件

for /r 参数 遍历搜索  
格式:`FOR /R [[drive:]path] %%variable IN (set) DO command [command-parameters]`  

举例:  
命令:(注意,该命令在 dos 窗口运行)  
    `D:\work\project\tmp\CI>for /r %i in (*.cfg) do @echo %i`  

输出:  

    D:\work\project\tmp\CI\ci_cfg\ci_scm_trunk.cfg
    D:\work\project\tmp\CI\ci_cfg\ci_ubackup.cfg
    D:\work\project\tmp\CI\zd15_lcd\setup\Release\apprun.cfg
    D:\work\project\tmp\CI\zd15_lcd\setup\Release\service.cfg
    D:\work\project\tmp\CI\zd15_lcd\src\service\apprun.cfg
    D:\work\project\tmp\CI\zd15_lcd\src\service\service.cfg  

方法二:(注意,该命令在批处理文件中运行)  
    `for /f %%i in ('dir /s /b /a-d *.cfg') do @ECHO %%i`  

解决路径中出现空格  
    `for /f “delims=*”%%i in ('dir /s /b /a-d *.cfg') do @ECHO %%`

Analyze wget source

Log of study wget source code

2012-9-27 00:04:30

  1. config
    ./configure
  2. compile
    make
  3. install
    make install
  4. uninstall
    make uninstall

compile log: (on virtualbox os ubuntu)

dennis@dennis-VBox:~/project/wget/wget-1.9$ ./configure
dennis@dennis-VBox:~/project/wget/wget-1.9$ ls
dennis@dennis-VBox:~/project/wget/wget-1.9$ make
// Error message: autoconf: Command not found
// install autoconf
dennis@dennis-VBox:~/project/wget/wget-1.9$ sudo apt-get install autoconf
dennis@dennis-VBox:~/project/wget/wget-1.9$ make
// Error message: makeinfo: Command not found
// install texinfo
dennis@dennis-VBox:~/project/wget/wget-1.9$ sudo apt-get install texinfo
dennis@dennis-VBox:~/project/wget/wget-1.9$ make

Binary file "wget" will be generated at wget-1.9/src/

todo
analyze Makefile

2012-9-26 00:06:18

  1. Home
  2. manual site
  3. manual generation script gendocs.sh
  4. pdf format manual

todo
compile wget source code