shell skills

创建目录树

1
mkdir -p {bin,lib,stub,opt,var/{log,tmp,run},devhome,backup,data}

初始化用户目录

1
2
mkdir -p {bin,lib,stub,opt,var/{log,tmp,run},devhome,backup,data};
ln -s var/log log; ln -s var/tmp tmp

Sudo 执行

1
2
3
4
5
6
7
8
SUDO_PASSWD=******
function Sudo()
{
# sent the pass and invoke a null command once.
echo $SUDO_PASSWD | sudo -S cat /dev/null >/dev/null 2>/dev/null
# execute the real command
sudo $@
}

删除缺省的目录,针对无桌面环境

1
rmdir 桌面 音乐 下载 文档 图片 视频 模板 公共的

使用&将stderr,stdout重定向到同一文件

1
2
# 等价于 find / -name "*.conf" >/tmp/find.log 2>&1
find / -name "*.conf" &>/tmp/find.log

ssh远程执行脚本

1
2
3
# 无须scp脚本到服务器,直接执行即可.
# ssh user@host bash <本地脚本路径
ssh user@host bash </tmp/1.sh

color echo

1
2
3
4
5
6
7
8
9
10
11
12
# write this to .bash_profile, .bashrc or your_own.rc
NORMAL=$(tput sgr0)
GREEN=$(tput setaf 2; tput bold)
YELLOW=$(tput setaf 3)
RED=$(tput setaf 1)
function red() { echo -e "$RED$*$NORMAL"; }
function green() { echo -e "$GREEN$*$NORMAL"; }
function yellow() { echo -e "$YELLOW$*$NORMAL"; }
# run
red "this is a red echo"
green "this is a green echo"
yellow "this is a yellow echo"

color stdout/stderr

请安装: colout

next