[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 464
  • Last Modified:

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 ?
0
F_A_H_D
Asked:
F_A_H_D
  • 3
  • 2
  • 2
  • +1
1 Solution
 
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
 
point_pleasantCommented:
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
Get quick recovery of individual SharePoint items

Free tool – Veeam Explorer for Microsoft SharePoint, enables fast, easy restores of SharePoint sites, documents, libraries and lists — all with no agents to manage and no additional licenses to buy.

 
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

Featured Post

Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

  • 3
  • 2
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now