Bash Shell 快捷键

六月 6th, 2010 xiao H Posted in shell 4 Comments »

CTRL

Ctrl + a - Jump to the start of the line
Ctrl + b - Move back a char
Ctrl + c - Terminate the command  //用的最多了吧?
Ctrl + d - Delete from under the cursor
Ctrl + e - Jump to the end of the line
Ctrl + f - Move forward a char
Ctrl + k - Delete to EOL
Ctrl + l - Clear the screen  //清屏,类似 clear 命令
Ctrl + r - Search the history backwards  //查找历史命令
Ctrl + R - Search the history backwards with multi occurrence
Ctrl + u - Delete backward from cursor // 密码输入错误的时候比较有用
Ctrl + xx - Move between EOL and current cursor position
Ctrl + x @ - Show possible hostname completions
Ctrl + z - Suspend/ Stop the command  Read the rest of this entry »
标签:,

ffmpeg 批量转换脚本

四月 2nd, 2010 xiao H Posted in shell No Comments »

从playingforchange.com 下载了好多FLV 文件放到手机上看,不过由于分辨率太高手机放起来一卡一卡的,所以要转换一下分辨率。

#/bin/sh
for f in *.flv
do
ffmpeg -i $f -s 320x240 sm-$f
done

检查当前目录下所有.flv 结尾的文件将其转换为 320×240 分辨率,新文件名为老文件名前加sm- 前缀。 Read the rest of this entry »

标签:,

我的 Conky 配置文件

五月 12th, 2009 xiao H Posted in shell, 日常桌面 15 Comments »

虽然监控系统状况的软件很多,但现在最受欢迎的该是Conky,Conky 小巧,漂亮,且配置方便简单。
CPU 温度读取部分用了sensors,硬盘温度读取用hddtemp。
conky
Read the rest of this entry »

标签:,

Iptables+tc 网吧每IP 限速脚本

五月 9th, 2009 xiao H Posted in shell 5 Comments »

网吧以前是没做限速的,但最近遇到几个狂爱看A片的哥们,用不知什么东西下载的,好几次把带宽占个精光,所以不得不做了限速。
总体思想很简单,为每个IP 打标,然后归入各自的tc 限速规则中去。
Read the rest of this entry »

标签:, , ,

dell 的 Remove Operating System 代码

一月 1st, 2009 xiao H Posted in shell 1 Comment »

在公社看到 WeiMingzhi 贴的Dell 预装SLED10机子上提供的删除OS 脚本,觉得蛮好特留一个备份。

title Remove Operating System
    root (hd0,2)
    kernel /vmlinuz root=/dev/disk/by-label/root ro init=/sbin/remove-os.sh resume=/dev/sda5 splash=silent showopts
    initrd /initrd

Read the rest of this entry »

标签:,

date 命令使用小技巧

十一月 24th, 2008 xiao H Posted in shell No Comments »

前两天在做为squid 做日志截断时零时学习了一下 date 命令的使用,这里做个小纪录

//昨日时间
date +%Y%m%d -d “-1 day”
//明日时间
date +%Y%m%d -d “+1 day”
//一月之间
date +%Y%m%d -d “-30 day”

Read the rest of this entry »

标签:

用 !$ 防止误操作

十一月 1st, 2008 xiao H Posted in shell 1 Comment »

作者:galeki 原文地址:http://www.linuxgem.org/posts/5769.html

shell 的通配符匹配非常强大,不过也非常危险,不少同学都碰到这样的问题,比如 rm a*,结果一个手抖,a 和星号之间多了个空格,结果目录下的文件都灰飞烟灭了……

bash 支持一个特殊的变量 !$,永远保存着前一条命令的最后一个参数,例如:

$ echo hello world
hello world
$ echo !$
world

Read the rest of this entry »

标签:

我常用的小shell

七月 4th, 2008 xiao H Posted in shell, 系统管理 No Comments »

下面是我平常用的一些bash shell 组合,方便我的日常管理。
清除所有arp 缓存

arp -n|awk '/^[1-9]/ {print "arp -d "$1}'|sh

显示打开连接数前10个机子的IP 和连接数

cat /proc/net/ip_conntrack | cut -d ' ' -f 10 | cut -d '=' -f 2 | sort | uniq -c | sort -nr | head -n 10

绑定已知机子的arp 地址

cat /proc/net/arp | awk '{print $1 " " $4}' |sort -t. -n +3 -4 > /etc/ethers

批量重命名

ls dirname | awk '{printf"mv %s file_%06d\n",$0,i++}' | sh

Per脚本实现eth0挂起后自动重启

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#!/usr/bin/perl -w
 
$fail_count = 0;
$cmd_result = '';
 
$cmd_result = `ping -w 4 61.130.107.193 |grep packet`;
 
if ($cmd_result =~ /100% packet loss/) {
$fail_count++;
if ($fail_count > 5) {
`ifdown eth0`;
`ifup eth0`;
} else {
$fail_count = 0;
}
}

自动从apnic记录中分离出网通,电信IP 段

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#!/bin/sh
FILE=/root/ip.txt
rm -f $FILE
wget http://ftp.apnic.net/apnic/stats/apnic/delegated-apnic-latest -O $FILE
grep 'apnic|CN|ipv4|' $FILE | cut -f 4,5 -d'|'|sed -e 's/|/ /g' | while read ip cnt
do
echo $ip:$cnt
mask=$(cat < < EOF | bc | tail -1
pow=32;
define log2(x) {
if (x<=1) return (pow);
pow--;
return(log2(x/2));
}
log2($cnt)
EOF)
echo $ip/$mask>> cn.net
NETNAME=`whois $ip@whois.apnic.net | sed -e '/./{H;$!d;}' -e 'x;/netnum/!d' |grep ^netname | sed -e 's/.*:      \(.*\)/\1/g' | sed -e 's/-.*//g'`
case $NETNAME in
CNC)
echo $ip/$mask >> CNCGROUP
;;
CHINANET|CNCGROUP)
echo $ip/$mask >> $NETNAME
;;
CHINANET|CNCGROUP)
echo $ip/$mask >> $NETNAME
;;
CHINATELECOM)
echo $ip/$mask >> CHINANET
;;
*)
echo $ip/$mask >> OTHER
;;
esac
done

去掉文件中的注释和空格

cat filename grep -v '^$' | grep -v '^#' > newfile
标签:

Page 1 of 212