Link to home
Start Free TrialLog in
Avatar of F_A_H_D
F_A_H_D

asked on

how to rename files to same files names plus .Z

OS is AIX 5.3
assume i have three files
test
test1
test2
 i want to rename it all to same files name with .Z
to be like that
test.Z
test1.Z
test2.Z

sure i know how to do it one by one .. but is there any chance to do it in one command ?
Avatar of point_pleasant
point_pleasant
Flag of United States of America image

for i in `ls test*`
do
   mv $i $i.z
done
Avatar of F_A_H_D
F_A_H_D

ASKER

can u explain more please .... how i can do that ?
ASKER CERTIFIED SOLUTION
Avatar of point_pleasant
point_pleasant
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Correct me if I am wrong but doesn't the .Z extension o. The file name indicate that the file is compressed? If so you just need to run the files through the compress program.
see also


man rename
Avatar of F_A_H_D

ASKER

correct
thank you very much
Avatar of woolmilkporc
Yes, I think leader716 is right!

Files with extension ".Z" are compressed.

Check if your files are already compressed and just have the wrong (or no) extension with e.g.

file test1

If you see e.g. "test1: compressed data block compressed 16 bit" the files are actually compressed and you should follow point_pleasant's suggestion.

If you don't see the above then compress the files with

for file in $(ls -1 test*); do compress $file; done

The files will get the ".Z" extension automatically.

The above one-liner just feeds the names of all files starting with "test" into the compress program, one by one (thus the "for" loop).

Please note that it's the digit "1", not the letter "l" in "ls -1".

wmp

Faster:

compress test*