linux 常用命令

1、小写字母转换大写字母

echo "aBcD"|tr 'a-z' 'A-Z'

2、大写字母转换小写字母

echo "aBcD"|tr 'A-Z' 'a-z'

3、当前脚本路径

basepath=$(cd `dirname $0`; pwd)

具体详细解释,请看http://www.cnblogs.com/FlyFive/p/3640267.html

4、常用日期变量

date +'%y%m%d%H%M%S'

输出格式为:20161027090005

date +'%y-%m-%d %H:%M:%S'

输出格式为:2016-10-27 09:00:05

5、sed常用命令

删除匹配test的行

sed -i '/test/d' /tmp/test.txt

修改/tmp/test.txt的内容test为test1

sed -i 's/test/test1/g' /tmp/test.txt

如遇到特殊字符,请把/替换为#或者其它字符.例如:sed -i 's#test#test1#g' /tmp/test.txt

6、行转列

执行命令:cat /tmp/test.txt

输出:

a b c

执行命令:

for parm in $(cat /tmp/test.txt)

do

echo $parm

done

输出结果:

a

b

c

7、列转行

执行命令:cat /tmp/test.txt

输出:

a

b

c

执行命令:cat /tmp/test.txt|xargs -r

输出:

a b c

8、获取linux系统版本

lsb_release -d

9、释放内存及脏页

echo 3 > /proc/sys/vm/drop_caches

10、列出当前目录下最大的10个子目录

du -s * |sort -rnk1|head -n 10|awk '{print $2}'|xargs -r du -sh 

11、查看子目录大小

du -h --max-depth=1

12、保留21天的备份

find /data/dbbak -name "*.gz" -mtime +21 -exec rm -f {} \;

 

posted @ 2016-10-27 09:25  hufangrui  阅读(185)  评论(0编辑  收藏  举报