$ls /tmp/somedir
ls: cannot access /tmp/somedir: No such file or directory
$mkdir !$
madir /tmp/somedir
27. 利用 python 搭建一个简单的 Web 服务器,可通过 http://$HOSTNAME:8000 访问。
python -m SimpleHTTPServer
28. 在 Vim 中无需权限保存编辑的文件。
:w !sudo tee %
29. 将上一条命令中的 foo 替换为 bar,并执行。
^foo^bar
30. 快速备份或复制文件。
cp filename{,.bak}
31. 将 ssh keys 复制到 user@host 以启用无密码 SSH 登录。
$ssh-copy-id user@host
32. 把 linux 桌面录制为视频。
ffmpeg -f x11grab -s wxga -r 25 -i :0.0 -sameq /tmp/out.mpg
33. man 妙用
man ascii
man test
34. 在 vim 中编辑上一条命令
fc
35. 删除0 字节文件或垃圾文件
find . -type f -size 0 -delete
find . -type f -exec rm -rf {} ;
find . -type f -name "a.out" -exec rm -rf {} ;
find . type f -name "a.out" -delete
find . type f -name "*.txt" -print0 | xargs -0 rm -f
36. 在编写SHELL 时显示多行信息
cat << EOF
+--------------------------------------------------------------+
| === Welcome to Tunoff services === |
+--------------------------------------------------------------+
EOF
注意,在指定结束符时,它必须是该行的唯一内容,并且该行必须以这个字符开头。
37. 如何给mysql建软链接
cd /usr/local/mysql/bin
for i in *
do ln /usr/local/mysql/bin/$i /usr/bin/$i
done
38. 获取IP地址:
ifconfig eth0 |grep "inet addr:" |awk '{print $2}'|cut -c 6-
39. 打开文件数目
lsof
40. 清除僵尸进程
ps -eal | awk '{ if ($2 == "Z"){ print $4}}' | kill -9
41. 打印唯一行
awk '!a[$0]++' file
42. 打印奇数行
awk 'i=!i' file
awk 'NR%2' file
43. 打印匹配行后的某一行
seq 10 | awk '/4/{f=4};--f==0{print;exit}'
44. 打印某行后后面的10行
cat file | grep -A100 string
cat file | grep -B100 string #前面
cat file | grep -C100 string #前后
sed -n '/string/,+100p'
awk '/string/{f=100}--f>=0'
45. 获取命令行最后一个参数
echo ${!#}
echo ${$#} #错误的尝试
46. 输出重定向
如果你愿你,可以将STDERR 和 STDOUT 的输出重定向到一个输出文件,为此,bash 提供了特殊的重定向符号 &>
ls file nofile &> /dev/null
我们如何在脚本里面重定向呢?没有什么特别之处,和普通重定向一样。
#!/bin/bash
#redirecting output to different locations










