# 文件拷贝
cp -r /etc /tmp
cd /tmp
tar cvf - /etc | tar xvf -
tar -cvf - filenames | bzip2 > archivefile.tar.bz2
# random number ($RANDOM 0~32767)
declare -i n=$RANDOM*10/32768
echo $n
# input in 30s
read -p "please input your name: " -t 30 name
# remove file or directory it contains special characters
ls -il
find . -inum inode_num -exec rm -rf {} \;
# Remove DOS CR(^M)
# vim
:set ff=unix
:%s/\r//g
:s/^M//gc
# tr
tr -d "\015" <dosfile >unixfile
tr -s "\r\n" "\n" <dosfile >unixfile
# sed (^M=Ctrl+^, Ctrl+v, Enter)
sed ’s/^M//’ dosfile > unixfile
# dos2unix
dos2uninx dosfile
# col
col -bx < dosfile
# 两天前
date --date="2 days ago" +%Y%m%d
# 修改系统时间
date -s 12/30/2008
date -s 15:36:00
date -s "2012-12-09 14:53:00"
# 硬件时钟与系统时钟同步
hwclock --systohc
*# @ 和 @和 @和区别
$@: [ "$1" "$2" "$3" $4" ],每个变量都是独立的
$*: [ "$1 $2 $3 $4" ],分割符默认为空格
# 忘记root密码
- 重启进入单人模式,使用passwd修改
- 以Live CD开机后挂载根目录,清空/etc/shadow中root密码字段
# 查询大文件
du | sort -nr | head
# 删除文件中的字母
tr --delete 'the' < mytest.txt
# 列出网卡名成
dmesg | grep -n --color=auto 'eth'
dmesg | grep -n --color=auto -B2 -A3 'eth' # B: before A:after
# 制作patch
diff -Naur passwd passwd.new > passwd.patch
patch -p0 < passwd.patch # update passwd
patch -R -p0 < passwd.patch # rollback passwd