LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 04-05-2010, 02:38 PM   #1
Sathallrin
LQ Newbie
 
Registered: Dec 2009
Distribution: Ubuntu Karmic
Posts: 13

Rep: Reputation: 0
gunzip doesn't give me back filename


I have looked around but can't figure out how to preserve the original file with gunzip (But I can with File Roller)

Here is a sample to show what I'm trying to do.

Create file called helloworld.txt with random data.

gzip file:
Code:
gzip helloworld.txt
rename file to some other random name
Code:
mv helloworld.txt.gz 12345.gz
unzip file:
Code:
gunzip 12345.gz
This results in 12345.txt however, my desired result is helloworld.txt

If I do the same thing but extract with File Roller, it works
Code:
gzip helloworld.txt
mv helloworld.txt.gz 12345.gz
file-roller -h 12345.gz
This gives me the file of helloworld.txt


How can I do this with a headless app such as gunzip (I don't care what program I use)? My main problem is the only solution I have found is to use file-roller which requires a GUI.
 
Old 04-05-2010, 02:45 PM   #2
smoker
Senior Member
 
Registered: Oct 2004
Distribution: Fedora Core 4, 12, 13, 14, 15, 17
Posts: 2,279

Rep: Reputation: 250Reputation: 250Reputation: 250
Don't rename it !
 
0 members found this post helpful.
Old 04-05-2010, 03:50 PM   #3
valen_tino
Member
 
Registered: Jan 2008
Posts: 105

Rep: Reputation: 28
==> create a gzip of the tarball
Code:
tar -zcvf filename1.tar.gz helloworld.txt
==> rename the file
Code:
mv filename1.tar.gz filename2.tar.gz
==> extract the file. This should retain your original filename i.e. helloworld.txt
Code:
tar -zxvf filename2.tar.gz
 
Old 04-06-2010, 07:35 AM   #4
Sathallrin
LQ Newbie
 
Registered: Dec 2009
Distribution: Ubuntu Karmic
Posts: 13

Original Poster
Rep: Reputation: 0
Thanks for the possible solution valen.

Above was just a reduced test case that could be tried so everyone could see what the issue was.

Part of the issue is the first 2 steps are out of my control. I get the gz files with a different name from the original files. So, I don't know what the filename in the gz was named to begin with.

However, File Roller is able to get the file name from the gz file when I extract it ( So I know the name is saved in the compressed file somewhere ). I'm just looking for a pure cli call I can use to automate the extraction on a headless machine since File Roller needs a gui.
 
Old 04-06-2010, 07:45 AM   #5
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
To restore the original name:
Code:
gunzip -N 12345.gz
this is valid except when the compression is made using the -n option, which does not preserve (save) the original name.
 
1 members found this post helpful.
Old 04-06-2010, 08:23 AM   #6
Sathallrin
LQ Newbie
 
Registered: Dec 2009
Distribution: Ubuntu Karmic
Posts: 13

Original Poster
Rep: Reputation: 0
Thanks colucix. That is exactly what I was looking for. No idea how I missed that flag. I read through the gunzip man page multiple times before resorting to posting here. I must have skimmed over the -N flag and only read the When compressing part and not the decompressing part.

Quote:
When compressing, always save the original file name and time stamp; this is the default. When decompressing, restore the original file name and time stamp if present. This option is useful on systems which have a limit on file name length or when the time stamp has been lost after a file transfer.
Thanks a bunch.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Maybe time to give something back... jnoake LinuxQuestions.org Member Intro 2 01-20-2009 08:02 PM
Give my kdm back! alaios Linux - Software 2 01-03-2009 12:41 PM
how to convert filename mojibake back into original encoding?? wordsmithy Linux - General 1 05-13-2008 02:13 AM
It's my time to give back! ipn1nj4 LinuxQuestions.org Member Intro 1 06-11-2004 03:08 PM
How do you give back? 46and2 Linux - General 14 10-11-2002 05:18 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 12:01 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration