Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

In a linux command line, you zip a file by:

zip -mqj file.txt

Now, I need to store 'file.txt' as 'file2.txt' in '', without renaming the file before zipping. When unzipped, the file should be called 'file2.txt'.

How can I store the file with a different name? Read through the MAN page and didn't find an answer.

share|improve this question
up vote 1 down vote accepted

Does creating a hard link to file.txt count?

ln file.txt file2.txt

Create file2.txt which points to the exact same inode as file.txt, without actually doubling the space

share|improve this answer

Hy there, this is my first answer so I hope I've done everything correct :-)

Here's my solution to your problem, a nice one-liner:

cp file.txt file2.txt | zip -mqj file2.txt

Hope I could help!

share|improve this answer
This is a good attempt, but the pipe is confusing. I think the person who asked didn't want to create a copy of the file first, but if he did, another way of doing this might be cp file.txt file2.txt && zip -mqj file2.txt && rm -f file2.txt - this would clean up the temporary file2.txt that got created. – Matt Simmons May 31 '09 at 18:05
thanks for pointing this out - I would post this approach, too (but you already did, thanks!) cp file.txt file2.txt && zip -mqj file2.txt (because of the -m switch the file already gets moved and there's no need to remove afterwards!) – Lypsis May 31 '09 at 18:09
Ah! Good call. I'm less familiar with zip than I am tar. thanks! – Matt Simmons May 31 '09 at 18:14
@Matt. Cant we just use mv instead of cp which wont create a copy, will rename the file, zip it and remove the copy to clear space. Just a thought. – Viky Jun 1 '09 at 4:37
@Viky - That would work fine, except one of the requests in the question was that we not rename the file. I think if we got more about the situation, a better answer would have presented itself, but as long as the person who asked the question is happy... – Matt Simmons Jun 1 '09 at 12:19


The solution below is the exact copy of the answer of @mkrnr on stackoverflow

You can use zipnote which should come with the zip package.

First build the zip archive with the myfile.txt file:

zip myfile.txt

Then rename myfile.txt inside the zip archive with:

printf "@ myfile.txt\n@=myfile2.txt\n" | zipnote -w

(Thanks to Jens for suggesting printf instead of echo -e.)

A short explanation of "@ myfile.txt\n@=myfile2.txt\n":

From zipnote -h: "@ name" can be followed by an "@=newname" line to change the name

And \n separates the two commands.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.