linux console下的命令们

Startup Engineering这们课一进入week3就铺天盖地扔来一堆命令,
一半左右我以前就知道吧,不过很多很好用的命令我却不经常常用,太容易忘了。
所以自己写个提纲,简单记录一下吧,忘了的时候好查,太常用的就不写了:

cp -a #带时间戳的cp
ln -sf data1.txt latest.txt #强制刷新的符号链接
nl #添加行号
yes | nl #常用计数器

head #前十行
tail #尾十行
cat a.txt b.txt #拼接文本
cut -f1 -d' ' *ptt #取出第一列,d指定分割符
paste a.ptt b.ptt #按列拼接文本

sort #排序
uniq -c #添加重复度,需先排序
uniq -d #只显示重复元素,需先排序
uniq -u #只显示唯一元素,需先排序,同sort -u
wc -l #查行数
wc -L #最长行长度
split -d -l 1000 *ptt subset.ptt. #拆分ppt文件为ppt.00、ppt.01等文件

sleep 60 & #后台执行sleep进程60秒
kill `ps xw | grep sleep | cut -f1 -d' ' | head -1` #反引号的神奇妙用

find /etc | nl #列文件目录
sudo apt-get install locate #安装locate
sudo updatedb #刷新全盘文件索引
locate fstab #全盘搜索文件名

df -Th #看磁盘
du -b #看目录

time sleep 5 #计时

# 天杀命令sed: http://www.catonmat.net/blog/wp-content/uploads/2008/09/sed1line.txt
sed -i ’s/\r/\n/g’ windows-newline-file.csv #转换windows格式去linux

# 天杀命令awk: http://www.pement.org/awk/awk1line.txt
tail -n+4 *ptt | awk -F"\t"{print $2, $3, $3 + 5}| head

# 天杀命令xargs: http://www.linuxjournal.com/article/6060
find /etc -name ’*\.sh’ | xargs head -2
# 两命令效果一样但前一个鲁棒性强
ls /etc/profile.d | xargs file
file /etc/profile.d/*

#抓站神命令wget
wget -w 2 -r -np -k -p http://www.stanford.edu/class/cs193p/cgi-bin/drupal/