Visit Our UNIX and Linux User Community

Unix Command to rename a file in a zipped folder

Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users Unix Command to rename a file in a zipped folder
# 1  
Old 04-21-2010
MySQL Unix Command to rename a file in a zipped folder


I am into automation work. Is there any UNIX command to rename a file in a zipped folder, without unzipping it..???

Thanks in advance..
# 2  
Old 04-21-2010
Seems to be possible with libzip, though that's just a function, not an executable. seeing what I can find that uses it...

---------- Post updated at 04:09 PM ---------- Previous update was at 03:55 PM ----------

Here's a quick program using libzip:
#include <stdio.h>
#include <zip.h>
#include <errno.h>

int main(int argc, char *argv[])
        int n, err, index=-1;
        struct zip *z;

        if(argc != 4)
                printf("syntax: %s oldname newname\n", argv[0]);

        z=zip_open(argv[1], 0, &err);

        if(z == NULL)
                char buf[512];
                zip_error_to_str(buf, 512, err, errno);
                fprintf(stderr, "Couldn't open zip: %s\n", buf);

        for(n=0; n<zip_get_num_files(z); n++)
                const char *name=zip_get_name(z, n, 0);
                if(strcmp(name, argv[2]) == 0)
        if(index < 0)
                fprintf(stderr, "Couldn't find %s\n", argv[2]);

        fprintf(stderr, "Found %s at %d\n", argv[2], index);

        if(zip_rename(z, index, argv[3]) < 0)
                fprintf(stderr, "Couldn't rename file\n");


Compile with -lzip.

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Rename folder

hi guys i have a group of directory like these p1( 15 - 16 ) p2( 17 -15 ) p1 ( 14 - 20 ) p2 ( 13 -17 ) .. . . directories contain numbers represent time i want to rename all directories and change all numbers in directories' name . for example p1( 15 -16 ) will change to... (16 Replies)
Discussion started by: mhs
16 Replies

2. Windows & DOS: Issues & Discussions

Transfer of zipped folder from windows desktop to UNIX server

Hi all, I'm a newbie to unix. My requirement is to create an automation script which will transfer a zipped folder from my/remote desktop to an unix server. Tools lik WinSCP shouldnt be used. No manual moving. I use putty to connect to server. I couldnt find any help on this topic. Should i use... (3 Replies)
Discussion started by: sherin22
3 Replies

3. Shell Programming and Scripting

Need help in writitng a script to rename file name and copy to other folder

Hi All, My requirement is as follows: A file (say abc) will be having list of the .txt file names. I need to read this abc file line by line and rename the .txt file names inside it and move them to other folder/path. Eg: abc ------- file1.txt file2.txt file3.txt Output (should... (1 Reply)
Discussion started by: pavan.yadalla
1 Replies

4. UNIX for Dummies Questions & Answers

Help with Unix file rename

Hi All, I have a unix file which is ceated with variable name, for example: FIRST_FILE_3456 and next time it will be FIRST_FILE_3457 and so on. I need to rename this file like PREV_FIRST_FILE_XXXX where XXXX is the variable part of the file FOR Example 3456 or 3457, etc. Please help to... (4 Replies)
Discussion started by: Mohammad T Khan
4 Replies

5. Shell Programming and Scripting

Multiple file rename (change in filename in unix with single command

Dear All, Please help ! i ham having 300 file with E.G. PMC1_4567.arc in seq. like PMC1_4568.arc,PMC1_4569.arc ...n and so on.. i want all those file to be rename like PMC_4567.arc ,PMC_4568.arc .. mean i want to remove 1 from first file name .. pls help.. (6 Replies)
Discussion started by: moon_22
6 Replies

6. Shell Programming and Scripting

Copy all zipped files from one folder to another

Hi everyone, when I try to copy *.gz files run cp within the correct source folder it works as follow: Source folder = C:/Documents and Settings/user/Recent papers/2771/ Destination folder = C:/Documents and Settings/user/My documents/1532/temp cp *.gz "C:/Documents and Settings/user/My... (2 Replies)
Discussion started by: cgkmal
2 Replies

7. UNIX for Advanced & Expert Users

UNIX: Command to compress folder and all files into a tar

I am trying to grab a folder and all the folders and files underneath it and send it from one computer to another. I basically want to compress the whole folder into a tar, tgz, or zip file so that it can be sent as one file. is there a command to compress a folder and all its contents into a tar... (7 Replies)
Discussion started by: kane4355
7 Replies

8. Shell Programming and Scripting

Rename folder based on containing XML file

Hi everyone. I'm in need of a solution where i need to rename a folder to a name that's inside an XML file in that folder. OS is Ubuntu 9.10 with Gnome. I've tried using grep, sed and xpath, but can't seem to find a solution. This is the simplified folder structure: FOLDER-NAME -... (4 Replies)
Discussion started by: CoolCow
4 Replies

9. UNIX for Dummies Questions & Answers

Disk Usage in GB and Unix command to find the biggest file/folder

Hi All, Please help me out 1) Command to find the disk usage in GB. I know that du -k will give in kilobites. 2) How to find the Biggest file/folder in a given set of files/folders. Thanks in advance Regards, Manas (8 Replies)
Discussion started by: manas6
8 Replies

10. UNIX for Dummies Questions & Answers

unix command to cound the number of files in a folder

Hi All Can some one help me out. Please tell the unix command to cound the number of files in a folder. Ungent please# Thanks manas (6 Replies)
Discussion started by: manas6
6 Replies

Featured Tech Videos