- 论坛徽章:
- 145
|
本帖最后由 jason680 于 2014-11-11 14:46 编辑
回复 4# kakaliu
1. check wrok directory
$ pwd
/tmp/day_backup
2. check files
$ ls
aaa hlhd_sql20141108.tar.gz
bbb hlhd_sql20141109.tar.gz
hlcjhd_sql20141107.tar.gz hlhd_sql20141110.tar.gz
hlcjhd_sql20141108.tar.gz niandu12_sql20141107.tar.gz
hlcjhd_sql20141109.tar.gz niandu12_sql20141108.tar.gz
hlcjhd_sql20141110.tar.gz niandu12_sql20141109.tar.gz
hlhd_sql20141107.tar.gz niandu12_sql20141110.tar.gz
#using 'find' utilty get FILE only
$ find . -maxdepth 1 -type f
./hlhd_sql20141110.tar.gz
./niandu12_sql20141108.tar.gz
./hlhd_sql20141107.tar.gz
./niandu12_sql20141109.tar.gz
./hlhd_sql20141109.tar.gz
./hlhd_sql20141108.tar.gz
./hlcjhd_sql20141107.tar.gz
./hlcjhd_sql20141108.tar.gz
./niandu12_sql20141107.tar.gz
./niandu12_sql20141110.tar.gz
./hlcjhd_sql20141110.tar.gz
./hlcjhd_sql20141109.tar.gz
3. using run=0 to make sure move(mv) command ...
$ find . -maxdepth 1 -type f | awk -vrun=0 'function xcmd(cmd,R,P){if(P)print cmd;if(R)system(cmd)}{p=gensub(/_.*/,"","",$1);xcmd("mkdir -p "p" 2>/dev/null",run,0);xcmd("mv "$1" "p,run,1)}'
mv ./hlhd_sql20141110.tar.gz ./hlhd
mv ./niandu12_sql20141108.tar.gz ./niandu12
mv ./hlhd_sql20141107.tar.gz ./hlhd
mv ./niandu12_sql20141109.tar.gz ./niandu12
mv ./hlhd_sql20141109.tar.gz ./hlhd
mv ./hlhd_sql20141108.tar.gz ./hlhd
mv ./hlcjhd_sql20141107.tar.gz ./hlcjhd
mv ./hlcjhd_sql20141108.tar.gz ./hlcjhd
mv ./niandu12_sql20141107.tar.gz ./niandu12
mv ./niandu12_sql20141110.tar.gz ./niandu12
mv ./hlcjhd_sql20141110.tar.gz ./hlcjhd
mv ./hlcjhd_sql20141109.tar.gz ./hlcjhd
4. set run=1 after make sure command without issue ...
$ find . -maxdepth 1 -type f | awk -vrun=1 'function xcmd(cmd,R,P){if(P)print cmd;if(R)system(cmd)}{p=gensub(/_.*/,"","",$1);xcmd("mkdir -p "p" 2>/dev/null",run,0);xcmd("mv "$1" "p,run,1)}'
mv ./hlhd_sql20141110.tar.gz ./hlhd
mv ./niandu12_sql20141108.tar.gz ./niandu12
mv ./hlhd_sql20141107.tar.gz ./hlhd
mv ./niandu12_sql20141109.tar.gz ./niandu12
mv ./hlhd_sql20141109.tar.gz ./hlhd
mv ./hlhd_sql20141108.tar.gz ./hlhd
mv ./hlcjhd_sql20141107.tar.gz ./hlcjhd
mv ./hlcjhd_sql20141108.tar.gz ./hlcjhd
mv ./niandu12_sql20141107.tar.gz ./niandu12
mv ./niandu12_sql20141110.tar.gz ./niandu12
mv ./hlcjhd_sql20141110.tar.gz ./hlcjhd
mv ./hlcjhd_sql20141109.tar.gz ./hlcjhd
Note: if you don't want to display the mv command message, you can set the print flag(P) to 0
5. check result
$ ls hl* ni*
hlcjhd:
hlcjhd_sql20141107.tar.gz hlcjhd_sql20141109.tar.gz
hlcjhd_sql20141108.tar.gz hlcjhd_sql20141110.tar.gz
hlhd:
hlhd_sql20141107.tar.gz hlhd_sql20141109.tar.gz
hlhd_sql20141108.tar.gz hlhd_sql20141110.tar.gz
niandu12:
niandu12_sql20141107.tar.gz niandu12_sql20141109.tar.gz
niandu12_sql20141108.tar.gz niandu12_sql20141110.tar.gz
|
|