[关闭]
@mSolo 2015-05-20T13:17:16.000000Z 字数 1652 阅读 1252

Linux 和 Vim 使用技巧收集

Linux Vim


Linux

.bash_profile

  1. export CDPATH=.:~:/etc:/var
  2. alias cd4="cd ../../../.."
  3. function mkdircd () { mkdir -p "$@" && eval cd "\"\$$#\""; }

grep、find、join、Xargs、nohup

  1. # grep John /etc/passwd
  2. jsmith:x:1082:1082:John Smith:/home/jsmith:/bin/bash
  3. jdoe:x:1083:1083:John Doe:/home/jdoe:/bin/bash
  4. # grep -v John /etc/passwd
  5. jbourne:x:1084:1084:Jason Bourne:/home/jbourne:/bin/bash
  6. # grep -c John /etc/passwd
  7. 2
  8. # grep -cv John /etc/passwd
  9. 39
  10. # grep -i john /etc/passwd
  11. jsmith:x:1082:1082:John Smith:/home/jsmith:/bin/bash
  12. jdoe:x:1083:1083:John Doe:/home/jdoe:/bin/bash
  13. # grep -ri john /home/users
  14. /home/users/subdir1/letter.txt:John, Thanks for your contribution.
  15. /home/users/name_list.txt:John Smith
  16. /home/users/name_list.txt:John Doe
  1. $ grep "^Nov 10" messages.1
  2. Nov 10 01:12:55 gs123 ntpd[2241]: time reset +0.177479 s
  3. Nov 10 01:17:17 gs123 ntpd[2241]: synchronized to LOCAL(0), stratum 10
  1. # find /etc -name "*mail*"
  2. # find / -type f -size +100M
  3. # find . -mtime +60 # 60 day
  4. # find /home/jsmith -type f -mtime +60 | xargs tar -cvf /tmp/`date '+%d%m%Y'_archive.tar`
  1. $ cat employee.txt
  2. 100 Jason Smith
  3. 200 John Doe
  4. 300 Sanjay Gupta
  5. 400 Ashok Sharma
  6. $ cat bonus.txt
  7. 100 $5,000
  8. 200 $500
  9. 300 $3,000
  10. 400 $1,250
  11. $ join employee.txt bonus.txt
  12. 100 Jason Smith $5,000
  13. 200 John Doe $500
  14. 300 Sanjay Gupta $3,000
  15. 400 Ashok Sharma $1,250
  1. find ~ -name ‘*.log -print0 | xargs -0 rm -f

Vim

  1. 指定行间搜索,例如行 13 ~ 23:/\%>12l\%<24lsearch来源
  2. 去掉数字后的非数字字符, 例如600000 浦发银行1,$s/\(\d\+\)\(\D\+\)/\1/g
  3. 保留前六位,例如000042 中证财通可持续发展100指数 : 1,$s/\(^.\{6\}\).*/\1/g
  4. 简单排序: 1,$!sort
添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注