We help IT Professionals succeed at work.

how to use cpio to unzip file

Jason Yu
Jason Yu asked
on
564 Views
Last Modified: 2013-01-07
Dear experts here;

I got a request from my coworker to retrieve one lost file from a backup archive.  when i check the archive, it's a big file with 67 GB, and the file ended with .cpio. How could I unzip this file and retrieve a file called Freight Survey Totals.xls (the original path of the file is  /u1/shares/ncshare/Freight Survey Totals.xls) Thank you a lot.

I am waiting for solution online, please help.


[root@triton DACS]# ls -l
total 65681548
-rw-rw-r-- 1 dacs dacs 67257892864 Dec 18 00:06 ncdacs2_20121217223057.cpio
drwxr-xr-x 2 root root        4096 Jan  4 13:23 tmp
Comment
Watch Question

AlexiosSEO Expert | IT Professional
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION
CERTIFIED EXPERT
Most Valuable Expert 2013
Top Expert 2013
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION

Author

Commented:
Hi, woolmilkporc:

i am running your command now, it looks like it's running there. but nothing displayed on the screen yet. I will leave it there. Hopefully, after 40 minutes, it can finish.

Ordinarily speaking, How long does it take to unzip a file from an archive of 67 G ?

Thank you , Kostasp and woolmilkporc for your timely reply. I am really appreciating your posts here. That's the reason I love EE.com.

Author

Commented:
for the above command, where is the unzipped file after running/

cpio -i "*Freight Survey Totals.xls*" < archivefile.cpio

Thank you.
CERTIFIED EXPERT
Most Valuable Expert 2013
Top Expert 2013

Commented:
It should have retained its original path, but with the leading "/" stripped, i. e. relative to your current directory:

/current/directory/u1/shares/ncshare/Freight Survey Totals.xls

I think you should repeat the extraction with "-v" specified, so you can see what cpio does.

cpio -iv "*Freight Survey Totals.xls*" < archivefile.cpio

If you're unsure  about the filename (spelling) try

cpio -ivt < archivefile.cpio

so you'll get a table of contents.

Author

Commented:
it finished, with the result as below:

[root@triton DACS]# cpio -i "*Freight Survey Totals.xls*" < ncdacs2_20121217223057.cpio
131363044 blocks



I am looking for the restored file.

Author

Commented:
I couldn't find the unzipped file, there is no new directory under current directory.
CERTIFIED EXPERT
Most Valuable Expert 2013
Top Expert 2013

Commented:
Yes, sorry, you must use the "-d" ("--make-directories") flag:

cpio -idv "*Freight Survey Totals.xls*" < archivefile.cpio

Author

Commented:
Ok, I am rerunning it. Hope this time it works.

Author

Commented:
it finished showing the result as below;

[root@triton DACS]# cpio -idv "*Freight Survey Totals.xls*" < ncdacs2_2012121722                                                                                                                     3057.cpio
131363044 blocks


but I still didn't find the upzipped file and folder. Please advise.
CERTIFIED EXPERT
Most Valuable Expert 2013
Top Expert 2013

Commented:
Please check the cotents of your archive.

cpio -ivt < ncdacs2_20121217223057.cpio

This will probably give too much output, so use something like "grep -i Survey" to filter:

cpio -ivt < ncdacs2_20121217223057.cpio | grep -i Survey

Once you found the file, use its full name to extract it.

The fact that it didn't work up to now could also be related to the spaces in the filename. I, personally, never have spaces in filenames (but I don't have to deal with Windows clients either).

If this is the culprit something like the following could help:

cpio -idv "*Freight*Survey*Totals.xls*" < ncdacs2_20121217223057.cpio

But before we continue - what's in the table of contents?

Author

Commented:
I am running the above command now. I don't like to use space in file names too, my coworkers, those wharehouse people, you know them. :)

I hope this time i will get luck.

Author

Commented:
can I open two putty sessions and run the above two commands at the same time.

I really want to see the result. If both sessions access the same file, will that be the problem?
CERTIFIED EXPERT
Most Valuable Expert 2013
Top Expert 2013

Commented:
No problem. cpio will not lock its input file.

Author

Commented:
The result is like this:

[root@triton DACS]# cpio -ivt < ncdacs2_20121217223057.cpio | grep -i Survey
131363044 blocks

Author

Commented:
when I check the folders, I see this, do you think these are unzipped files?

[mis@triton DACS]$ ls -l
total 93104480
-rw-rw-r-- 1 dacs dacs 22960521903 Oct 13 00:31 ncdacs2_20121012223052.cpio.gz
-rw-rw-r-- 1 dacs dacs  9601408282 Jan  1 02:38 ncdacs2_20121231223503.cpio.gz
-rw-rw-r-- 1 dacs dacs 19793141418 Jan  2 07:32 ncdacs2_20130101223444.cpio.gz
-rw-rw-r-- 1 dacs dacs 19704611095 Jan  3 00:03 ncdacs2_20130102223047.cpio.gz
-rw-rw-r-- 1 dacs dacs 23279272596 Jan  4 00:25 ncdacs2_20130103223058.cpio.gz
[mis@triton DACS]$
CERTIFIED EXPERT
Most Valuable Expert 2013
Top Expert 2013

Commented:
These are old and not so old manually gzipped cpio archives. cpio  does not zip/unzip on its own.

There is no file containing the string "Survey" in your archive.

Let's hope that the file has been written to the archive at all (spaces?).

What do you get with

cpio -ivt < ncdacs2_20121217223057.cpio | grep -i Freight

And please display the whole toc (without "| grep ...", that is). What do you see?

Author

Commented:
This command finished:

[root@triton DACS]# cpio -idv "*Freight*Survey*Totals.xls*" < ncdacs2_2012121722
131363044 blocks

Author

Commented:
Can we use this file:

-rw-rw-r-- 1 dacs dacs  9601408282 Jan  1 02:38 ncdacs2_20121231223503.cpio.gz

I think this backup is very new and it's just three days before the file lost.

Could we unzip this file and see if the lost file is there?

Thanks.

Author

Commented:
what does the output number mean? Like this one

131363044 blocks

Author

Commented:
it looks like this time got some files unzipped. It shows some files with "freight" in the file names.

Author

Commented:
It indeed unzipped some files, but not the files they lost. That means this archive doesn't have this file backuped up, right?

[root@triton DACS]# cpio -idv "*Freight*Survey*Totals.xls*" < ncdacs2_2012121722
131363044 blocks
[root@triton DACS]# ^C
[root@triton DACS]# cpio -ivt < ncdacs2_20121217223057.cpio | grep -i Freight
-rw-rw----   1 201      users      111872 Mar  1  2012 u3/u4backup/datacoll/obj/                                                                                                                     old/freight1.cob
-rw-rw----   1 201      users      111872 Mar  1  2012 u3/u4backup/datacoll/obj/                                                                                                                     old/freight1p.cob
-rw-rw----   1 201      users      111872 Mar  1  2012 u3/u4backup/datacoll/obj/                                                                                                                     freight1.cob
-rw-rw----   1 201      users      112128 Mar  1  2012 u3/u4backup/datacoll/obj/                                                                                                                     freight1p.cob
-rw-rw----   1 10005    10003        9456 Feb 21  2007 u3/u4backup/mysql/data21/                                                                                                                     prod/FreightCarriers.frm
-rw-rw----   1 10005    10003        9211 Feb 21  2007 u3/u4backup/mysql/data21/                                                                                                                     prod/FreightCharges.frm
-rw-rw----   1 10005    10003        9239 Feb 21  2007 u3/u4backup/mysql/data21/                                                                                                                     prod/FreightDestinations.frm
-rw-rw----   1 10005    10003        9220 Feb 21  2007 u3/u4backup/mysql/data21/                                                                                                                     prod/FreightMethods.frm
-rw-rw----   1 10005    10003        9344 Feb 21  2007 u3/u4backup/mysql/data21/                                                                                                                     prod/FreightProNumbers.frm
-rw-rw----   1 10005    10003        9168 Feb 21  2007 u3/u4backup/mysql/data21/                                                                                                                     prod/FreightRates.frm
-rw-rw----   1 10005    10003        9066 Feb 21  2007 u3/u4backup/mysql/data21/                                                                                                                     prod/FreightServices.frm
-rw-rw----   1 10005    10003        9216 Feb 21  2007 u3/u4backup/mysql/data21/                                                                                                                     prod/FreightZones.frm
-rw-r-----   1 10004    ftp         54410 Sep 27  2005 u3/u4backup/spnotes/Custo                                                                                                                     mer_Special_Instructions/Eldorado_Furniture/Shipping_Instructions/Freight.pdf
-rw-r-----   1 10004    ftp        757167 Sep 27  2005 u3/u4backup/spnotes/Custo                                                                                                                     mer_Special_Instructions/Sears/Shipping_Instructions/Routing\ Guide\ -\ The_Grea                                                                                                                     t_Indoors\ (Direct_To_Store\ -\ freight\ collect).pdf
-rw-r-----   1 10004    ftp        765479 Sep 27  2005 u3/u4backup/spnotes/Custo                                                                                                                     mer_Special_Instructions/Sears/Shipping_Instructions/Routing\ Guide\ -\ The_Grea                                                                                                                     t_Indoors\ (Direct_To_Warehouse\ -\ freight\ collect\ &\ prepaid).pdf
-rw-r-----   1 10004    ftp       1151137 Sep 27  2005 u3/u4backup/spnotes/Custo                                                                                                                     mer_Special_Instructions/Sears/Shipping_Instructions/Routing\ Guide\ -\ The_Grea                                                                                                                     t_Indoors\ (RRC\ -\ freight\ collect).pdf
-rw-rw----   1 10001    10001      111872 Sep 26  2010 u3/u4backup/testcoll/obj/old/freight1.cob
-rw-rw----   1 10001    10001      111872 Sep 26  2010 u3/u4backup/testcoll/obj/old/freight1p.cob
-rw-rw----   1 10001    10001      111872 Mar  1  2012 u3/u4backup/testcoll/obj/freight1.cob
-rw-rw----   1 10001    10001      112128 Mar  1  2012 u3/u4backup/testcoll/obj/freight1p.cob
-rw-rw----   1 201      users      110848 May 25  2006 u4/datacoll/obj/old/freight1.cob
-rw-rw----   1 201      users      111104 Feb 27  2007 u4/datacoll/obj/old/freight1p.cob
-rw-rw----   1 201      users      111872 Sep 26  2010 u4/datacoll/obj/freight1.cob
-rw-rw----   1 201      users      111872 Sep 26  2010 u4/datacoll/obj/freight1p.cob
-rw-rw----   1 10001    10001      111616 Jun  1  2010 u4/testcoll/obj/old/freight1.cob
-rw-rw----   1 10001    10001      111616 Jun  1  2010 u4/testcoll/obj/old/freight1p.cob
-rw-rw----   1 10001    10001      111872 Sep 26  2010 u4/testcoll/obj/freight1.cob
-rw-rw----   1 10001    10001      111872 Sep 26  2010 u4/testcoll/obj/freight1p.cob
-rw-r-----   1 10004    ftp         54410 Sep 27  2005 u4/spnotes/Customer_Special_Instructions/Eldorado_Furniture/Shipping_Instructions/Freight.pdf
-rw-r-----   1 10004    ftp        757167 Sep 27  2005 u4/spnotes/Customer_Special_Instructions/Sears/Shipping_Instructions/Routing\ Guide\ -\ The_Great_Indoors\ (Direct_To_Store\ -\ freight\ collect).pdf
-rw-r-----   1 10004    ftp       1151137 Sep 27  2005 u4/spnotes/Customer_Special_Instructions/Sears/Shipping_Instructions/Routing\ Guide\ -\ The_Great_Indoors\ (RRC\ -\ freight\ collect).pdf
-rw-r-----   1 10004    ftp        765479 Sep 27  2005 u4/spnotes/Customer_Special_Instructions/Sears/Shipping_Instructions/Routing\ Guide\ -\ The_Great_Indoors\ (Direct_To_Warehouse\ -\ freight\ collect\ &\ prepaid).pdf
-rw-rw----   1 10005    10003        9456 Feb 21  2007 u4/mysql/data21/prod/FreightCarriers.frm
-rw-rw----   1 10005    10003        9211 Feb 21  2007 u4/mysql/data21/prod/FreightCharges.frm
-rw-rw----   1 10005    10003        9239 Feb 21  2007 u4/mysql/data21/prod/FreightDestinations.frm
-rw-rw----   1 10005    10003        9220 Feb 21  2007 u4/mysql/data21/prod/FreightMethods.frm
-rw-rw----   1 10005    10003        9344 Feb 21  2007 u4/mysql/data21/prod/FreightProNumbers.frm
-rw-rw----   1 10005    10003        9168 Feb 21  2007 u4/mysql/data21/prod/FreightRates.frm
-rw-rw----   1 10005    10003        9066 Feb 21  2007 u4/mysql/data21/prod/FreightServices.frm
-rw-rw----   1 10005    10003        9216 Feb 21  2007 u4/mysql/data21/prod/FreightZones.frm
131363044 blocks
CERTIFIED EXPERT
Most Valuable Expert 2013
Top Expert 2013
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION
CERTIFIED EXPERT
Most Valuable Expert 2013
Top Expert 2013

Commented:
4) Yes, the file is not there. Seems there is nothing from /u1/... present at all.

Seems you have some special script in place to create the archive which prepends a backslash to the spaces in filenames.

So, if the file were present, this format "*Freight*Survey*Totals.xls" should  have done the trick.

Author

Commented:
yes, thank you very much. Since the office in North Carolinze have to close now, I have to ask them to switch the tape out because I don't want to this archive be overwritten. I have to keep working on this next Monday.

But i really feel moved by your help. I should treat you for a dinnder for this work.

I am in Los Angeles, CA. my email is condescendent@gmail.com. Give me an email when you have time. I want to make friends with you.

Author

Commented:
From the output, it looks like all the recoverried files were written back to their original position, am I right?
CERTIFIED EXPERT
Most Valuable Expert 2013
Top Expert 2013

Commented:
No. Two things:

1) You used the -t flag, which means "table of contents". So nothing was written, you just saw the list of files contained in the archive.

2) Please note the missing leading slash. e. g. in "u4/mysql/data21/prod/FreightZones.frm"

So even if the files had been written (they haven't!) their new position would be relative to your current directory, so if you were in /tmp you would have written "/tmp/u4/mysql/data21/prod/FreightZones.frm". Got the difference? But once more, nothing has been written!

Author

Commented:
thank you very much, woolmilkporc, I learned a lot.


I have to go to lunch now, it's 3:32 PM. here in CA. It's a really nice experience to working with you. I hope you have a wonderful weekend.
CERTIFIED EXPERT
Most Valuable Expert 2013
Top Expert 2013

Commented:
OK,

it's 0:38 AM (Saturday) here in Ol' Europe.

Enjoy your meal, and have a nice weekend, too.

Always glad to help

wmp

Author

Commented:
got it solved, thank you.

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.