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 ?
LVL 3
F_A_H_DAsked:
Who is Participating?
 
point_pleasantConnect With a Mentor Commented:
you can do it from the command line or from a file.


with what ever editor you use open a file call it say mymove.sh

add the four lines from above
save the file
add execute permission to it chmod +x mymove.sh
go to the direstory where you test files are
then just run the file

$PATH_to_file/mymoves.sh

you can use sh -x $PATH_to_file/mymove.sh to see every command as it is executed

0
 
point_pleasantCommented:
for i in `ls test*`
do
   mv $i $i.z
done
0
 
F_A_H_DAuthor Commented:
can u explain more please .... how i can do that ?
0
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
leader716Commented:
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.
0
 
point_pleasantCommented:
see also


man rename
0
 
F_A_H_DAuthor Commented:
correct
thank you very much
0
 
woolmilkporcCommented:
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

0
 
woolmilkporcCommented:
Faster:

compress test*
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.