最受欢迎的10个 Linux 单行命令

星期三, 二月 16th, 2011 Posted in shell | No Comments »

下面是来自 Commandlinefu 网站由用户投票决出的 10 个最酷的 Linux 单行命令。

sudo !!

以 root 帐户执行上一条命令。

python -m SimpleHTTPServer

利用 Python 搭建一个简单的 Web 服务器,可通过 http://$HOSTNAME:8000 访问。

标签:

Bash Shell 快捷键

星期日, 六月 6th, 2010 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 

标签:,

dell 的 Remove Operating System 代码

星期四, 一月 1st, 2009 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

标签:,

我常用的小shell

星期五, 七月 4th, 2008 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

标签:

几个有用的bash shell组合

星期五, 三月 7th, 2008 Posted in shell | No Comments »

ps aux | awk '{ if ($3 &gt; 8 ) print $2}'

这个是列出cpu 占有率高于 8% 的进程的PID

cat /proc/net/arp | awk '{print $4 $1}' &gt;&gt;/etc/ethers

读取当前机器arp 表并把得到的mac 地址和相应的ip 地址添加到/etc/ethers 文件中去

标签:,

Bash的输入输出重定向

星期一, 三月 3rd, 2008 Posted in shell | 1 Comment »

使用Bash可以方便的用<和>实现输出输入的重定向,本文讨论重定向的一些细节和技巧。本文介绍部分是对Bash Quick Reference相关内容的翻译。

基础知识

文件描述符(File Descriptor),用一个数字(通常为0-9

标签:,


Page 1 of 11