Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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

zip -mqj archive.zip file.txt

Now, I need to store 'file.txt' as 'file2.txt' in 'archive.zip', 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

2 Answers 2

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 archive.zip file2.txt

Hope I could help!

share|improve this answer
2  
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 archive.zip 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
2  
thanks for pointing this out - I would post this approach, too (but you already did, thanks!) cp file.txt file2.txt && zip -mqj archive.zip 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

Your Answer

 
discard

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.