Chinaunix首页 | 论坛 | 博客
  • 博客访问: 351944
  • 博文数量: 26
  • 博客积分: 495
  • 博客等级: 下士
  • 技术积分: 562
  • 用 户 组: 普通用户
  • 注册时间: 2010-04-26 13:50
文章分类

全部博文(26)

文章存档

2015年(9)

2014年(6)

2013年(7)

2012年(2)

2011年(2)

分类: Python/Ruby

2011-06-10 10:17:16

1.平级切换目录eg:从/a/b/c/kk  切换到 /a/b/f/kk

cd ${PWD/c/f}  #主要是shell的字符串替换   

2.随机生成一个ip

echo $((RANDOM%256)).$((RANDOM%256)).$((RANDOM%256)).$((RANDOM%256))

3.this will fill your shell with random data, parts of it highlighted  (偷懒专用)

cat /dev/urandom | hexdump -C |grep --color=yes -E "(ca|fe|3d|42|e1|b3|ae|f8)" | perl -MTime::HiRes -pne "Time::HiRes::usleep(rand()*1000000)"    

4.Selecting a random file/folder of a folder random file from files in directory

ls -1 | shuf -n 1

5.随机生成合法的mac地址

python -c "from itertools import imap; from random import randint; print ':'.join(['%02x'%x for x in imap(lambda x:randint(0,255), range(6))])"

for i in {1..6}; do printf "%0.2X:" $(($RANDOM % 0x100 )); done | sed 's/:$/\n/'

for i in {1..6}; do printf "%0.2X:" $[ $RANDOM % 0x100  ]; done | sed 's/:$/\n/'
                
h=0123456789ABCDEF;for c in {1..12};do echo -n ${h:$(($RANDOM%16)):1};if [[ $((c%2)) = 0 && $c != 12 ]];then echo -n :;fi;done;echo
            
 6.将一个字符串split 成数组:
awk:echo ‘a s d a da daa’  |awk '{split($0,arr);print arr[1]}'
herestring: read -a ARR <<< "a s d a da daa";echo ${ARR[2]}        

7.让自己的终端显示时间
                
export PS1="(\@) $PS1"

8.Create date-based tgz of current dir, runs in the background, Here is the full alias
alias tarred='( ( D=`builtin pwd`; F=$(date +$HOME/`sed "s,[/ ],#,g" <<< ${D/${HOME}/}`#-%F.tgz); tar --ignore-failed-read --transform "s,^${D%/*},`date +${D%/*}.%F`,S" -czPf "$"F "$D" &>/dev/null ) & )'
                
9.显示bash 256种颜色所对应的数值
for i in {0..255}; do echo -e "\e[38;05;${i}m${i}"; done | column -c 80 -s '  '; echo -e "\e[m"  

10.模拟黑客帝国的字符屏幕 :)[Blue Matrix]
while [ 1 -lt 2 ]; do i=0; COL=$((RANDOM%$(tput cols)));ROW=$((RANDOM%$(tput cols)));while [ $i -lt $COL ]; do tput cup $i $ROW;echo -e "\033[1;34m" $(cat /dev/urandom | head -1 | cut -c1-1) 2>/dev/null ; i=$(expr $i + 1); done; done
                    
11.快速查阅date 日期表示帮助文档
alias dateh='date --help|sed "/^ *%a/,/^ *%Z/!d;y/_/!/;s/^ *%\([:a-z]\+\) \+/\1_/gI;s/%/#/g;s/^\([a-y]\|[z:]\+\)_/%%\1_%\1_/I"|while read L;do date "+${L}"|sed y/!#/%%/;done|column -ts_'
             
12.迅速搭建webserver (在文件传输方面能派上用场,wget curl)
python -m SimpleHTTPServer 
Serve current directory tree at


13.This command will start a simple SMTP server listening on port 1025 of localhost. This server simply prints to standard output all email headers and the email body.

python -m smtpd -n -c DebuggingServer localhost:1025

阅读(2619) | 评论(0) | 转发(1) |
给主人留下些什么吧!~~