?

Log in

No account? Create an account

Previous Entry | Next Entry

Move all *.txt.bak files to *.txt

This is always a day-2-day task, taking backups of all the files, and removing backup extn from the files sometime.
Here is something to do that.

[jsaikia] ~/prac/blog/patch $ ls
as.txt.bak  bs.txt.bak  cs.txt.bak

[jsaikia] ~/prac/blog/patch $ ls | while read file
> do
> mv $file `echo $file | sed 's/.bak$//g'`
> done

One more way:

[jsaikia] ~/prac/blog/patch $ ls | while read file
> do
> mv $file `basename $file .bak`
> done


[jsaikia] ~/prac/blog/patch $ ls
as.txt  bs.txt  cs.txt

And if you have to do the above operation with all the files in the present as well as sub-dirs , use the same with "find", this helps.

[jsaikia] ~/prac/blog $ find patch/ -name *.bak -type f -print
patch/dir2/ds.txt.bak
patch/as.txt.bak
patch/bs.txt.bak
patch/cs.txt.bak

[jsaikia] ~/prac/blog $ find patch/ -name *.bak -type f -print | while read file
> do
> mv $file `echo $file | sed 's/.bak$//g'`
> done

Profile

jaduks
Jadu Kumar Saikia

Latest Month

January 2008
S M T W T F S
  12345
6789101112
13141516171819
20212223242526
2728293031  
Powered by LiveJournal.com
Designed by chasethestars