linux系统管理技巧(一)

 本文来自: allcommands php

整理其比较实用的好的程序,并翻译过来。less

1、在当前目录及子目录下搜索全部后缀为 .php 的文件,而且将 字符串 baidu.com 替换成 opendoc.com.cn
find -name *.php |xargs perl -pi -e 's|baidu.com|opendoc.com.cn|g';
sed -i "s/baidu.com/opendoc.com.cn/g" `grep baidu.com -rl ./`ide

2、将当前目录文件名所有转换成小写
for i in *; do mv "$i" "$(echo $i|tr A-Z a-z)"; donesvn

3、查找二个文件相同的内容
grep -Fx -f file1 file2
sort file1 file2 | uniq -dspa

4、查找file2里 file1里没有的内容
grep -Fxv -f file1 file2翻译

5、自动更新SVN的一个目录
for d in $(find . -maxdepth 1 -type d -name '[^.]*'); do cd "$d"; svn up; cd ..; done排序

6、查找当前文件列表 文件与组没有修改时间排序
find . -type f | xargs ls -ltrhg
l: 全部信息
t: 修改时间排序
r: 倒序
h: 大小 M K
g: 用户组字符串

7、找到文件,将其与一个可读的信息输出列表
find . -type f | sed 's,.*,stat "&" | egrep "File|Modify" | tr "\\n" " " ; echo ,' | sh | sed 's,[^/]*/\(.*\). Modify: \(....-..-.. ..:..:..\).*,\2 \1,' | sortit

find . -type f -exec ls -tr {} +io

find . -type f | sed 's,.*,stat "&" | egrep "File|Modify" | tr "\\n" " " ; echo ,' | sh | sed 's,[^/]*/\(.*\). Modify: \(...........\).*,\2 \1,' | sort

ls -rl --time-style=+%s * | sed '/^$/,/^total [0-9]*$/d' | sort -nk6

8、查找文件和他们按修改时间排序的列表
ls -rl --time-style=+%s * | sed '/^$/,/^total [0-9]*$/d' | sort -nk6

9、查找N天前的文件,按时间排序
find . -type f -mtime -14 -exec ls -ltd \{\} \; | less

10、配置PS aliases
export PSOA='user,pid,time,state,command' ; function _ps { /bin/ps $@ ; } ; alias psa='_ps ax -o

$PSOA'
#ps aliases
PSO='user,pid,ppid,%cpu,%mem,time,start,state,command'
PSOA='user,pid,time,state,command'
PSOL='user,pid,ppid,%cpu,%mem,nice,pri,etime,time,tt,state,ucomm'
export PSO PSOA PSOL
function _ps { /bin/ps $@ ; }
alias ps='_ps ax -o $PSO'
alias psa='_ps ax -o $PSOA'
alias psl='_ps ax -o $PSOL'
alias psm='_ps -U $USER -o $PSOA'

11、逐渐打印各行 awk 'BEGIN{ORS=""}NR!=1&&FNR==1{print "\n"}{print}END{print "\n"}' *.txt

相关文章
相关标签/搜索