1. 批量解压多个 .tgz 包:
查看目录下所有文件:
[zhang@localhost begnning_linux_proggramming]$ ls 780470147627-code-ch01.tgz 780470147627-code-ch06.tgz 780470147627-code-ch11.tgz 780470147627-code-ch16.tar.gz temp.sh 780470147627-code-ch02.tgz 780470147627-code-ch07.tgz 780470147627-code-ch12.tgz 780470147627-code-ch17.tar.gz 780470147627-code-ch03.tgz 780470147627-code-ch08.tgz 780470147627-code-ch13.tgz ReadMe.txt 780470147627-code-ch04.tgz 780470147627-code-ch09.tgz 780470147627-code-ch14.tgz 780470147627-code-ch05.tgz 780470147627-code-ch10.tgz 780470147627-code-ch15.tgz
[zhang@localhost begnning_linux_proggramming]$ for i in `ls *.tgz`; do echo tar zxvf $i; done;[zhang@localhost begnning_linux_proggramming]$
tar zxvf 780470147627-code-ch01.tgz
tar zxvf 780470147627-code-ch02.tgz
tar zxvf 780470147627-code-ch03.tgz
tar zxvf 780470147627-code-ch04.tgz
tar zxvf 780470147627-code-ch05.tgz
tar zxvf 780470147627-code-ch06.tgz
tar zxvf 780470147627-code-ch07.tgz
tar zxvf 780470147627-code-ch08.tgz
tar zxvf 780470147627-code-ch09.tgz
tar zxvf 780470147627-code-ch10.tgz
tar zxvf 780470147627-code-ch11.tgz
tar zxvf 780470147627-code-ch12.tgz
tar zxvf 780470147627-code-ch13.tgz
tar zxvf 780470147627-code-ch14.tgz
tar zxvf 780470147627-code-ch15.tgz[zhang@localhost begnning_linux_proggramming]$
一次性解压:
[zhang@localhost begnning_linux_proggramming]$ for i in `ls *.tgz`; do tar zxvf $i; done chapter01/ chapter01/bill.c chapter01/lib.h chapter01/program.c chapter01/hello.c chapter01/fred.c ch02/ ch02/app/ ch02/app/cd_db ch02/app/title.cdb ch02/app/tracks.cdb ch02/case1
chapter15/server4.c chapter15/client2.c chapter15/server2.c chapter15/Makefile [zhang@localhost begnning_linux_proggramming]$ [zhang@localhost begnning_linux_proggramming]$
2. 批量文件重命名
[zhang@localhost begnning_linux_proggramming]$ ls 780470147627-code-ch01.tgz 780470147627-code-ch07.tgz 780470147627-code-ch13.tgz ch06 ch14 chapter11 780470147627-code-ch02.tgz 780470147627-code-ch08.tgz 780470147627-code-ch14.tgz ch07 chapter01 chapter15 780470147627-code-ch03.tgz 780470147627-code-ch09.tgz 780470147627-code-ch15.tgz ch08 chapter03 ReadMe.txt 780470147627-code-ch04.tgz 780470147627-code-ch10.tgz 780470147627-code-ch16.tar.gz ch09 chapter04 temp.sh 780470147627-code-ch05.tgz 780470147627-code-ch11.tgz 780470147627-code-ch17.tar.gz ch12 chapter05 780470147627-code-ch06.tgz 780470147627-code-ch12.tgz ch02 ch13 chapter10 [zhang@localhost begnning_linux_proggramming]$ [zhang@localhost begnning_linux_proggramming]$ [zhang@localhost begnning_linux_proggramming]$ rename chapter ch chapter?? [zhang@localhost begnning_linux_proggramming]$ ls 780470147627-code-ch01.tgz 780470147627-code-ch06.tgz 780470147627-code-ch11.tgz 780470147627-code-ch16.tar.gz ch04 ch09 ch14 780470147627-code-ch02.tgz 780470147627-code-ch07.tgz 780470147627-code-ch12.tgz 780470147627-code-ch17.tar.gz ch05 ch10 ch15 780470147627-code-ch03.tgz 780470147627-code-ch08.tgz 780470147627-code-ch13.tgz ch01 ch06 ch11 ReadMe.txt 780470147627-code-ch04.tgz 780470147627-code-ch09.tgz 780470147627-code-ch14.tgz ch02 ch07 ch12 temp.sh 780470147627-code-ch05.tgz 780470147627-code-ch10.tgz 780470147627-code-ch15.tgz ch03 ch08 ch13 [zhang@localhost begnning_linux_proggramming]$ [zhang@localhost begnning_linux_proggramming]$
[zhang@localhost begnning_linux_proggramming]$ ls alltgz ch02 ch04 ch06 ch08 ch10 ch12 ch14 chap16_src ReadMe.txt ch01 ch03 ch05 ch07 ch09 ch11 ch13 ch15 chap17_src temp.sh [zhang@localhost begnning_linux_proggramming]$ [zhang@localhost begnning_linux_proggramming]$ rename chap ch chap*
[zhang@localhost begnning_linux_proggramming]$ ls
alltgz ch02 ch04 ch06 ch08 ch10 ch12 ch14 ch16_src ReadMe.txt
ch01 ch03 ch05 ch07 ch09 ch11 ch13 ch15 ch17_src temp.sh
[zhang@localhost begnning_linux_proggramming]$
3. vim 下下批量删除/替换
命令模式下 批量删除 ^M (Windows 把\r\n 而不是 \n 作为换行符)
:%s/^M//gc
等价为
:%s/\r//gc
^M 即 \r 输入为 ctrl + v, ctrl + m
g选项表示全局替换,c选项表示每次替换都需要确认。