1823920 Members
3198 Online
109667 Solutions
New Discussion юеВ

Re: cpio command

 
sandeep mathur
Respected Contributor

cpio command

what is the use of cpio command and how to use it
gimmme an example.

thanks in advance. points assured.
9 REPLIES 9
Aneesh Mohan
Honored Contributor

Re: cpio command

Hi Sandeep ,

Copy using cpio

#find /sourcedir -depth -xdev |cpio -pdlmuvax /destination


Thanks,
Aneesh
Kapil Jha
Honored Contributor

Re: cpio command

cpio-copy file archives in and out;
duplicate directory trees

I think best way is man cpio.

well example is like
cpio -o (copy out)
cpio -i (copy in)
cpio -p (directory copy)

To copy files to magnetic tape,
# cpio -ov < file-list -O/dev/tape/tape0

N number of usages are there....
Hope this would help.
BR,
Kapil
I am in this small bowl, I wane see the real world......
melvyn burnard
Honored Contributor

Re: cpio command

how qabout reading the man page??

man cpio
My house is the bank's, my money the wife's, But my opinions belong to me, not HP!
Aneesh Mohan
Honored Contributor

Re: cpio command

Hi Sandeep ,

Cpio command.
cpio command is useful to backup the file systems. It copy file archives in from or out to tape or disk, or to another location on the local machine. Its syntax is
cpio flags [options]

It has three flags, -i, -o, -p
cpio -i [options] [patterns]
cpio -i copy in files who names match selected patterns.
If no pattern is used all files are copied in.
It is used to write to a tape.
cpio -o
Copy out a list of files whose name are given on standard output.
cpio -p
copy files to another directory on the same system.
Options
-a reset access times of input files.
-A append files to an archive (must use with -o).
-b swap bytes and half-words. Words are 4 bytes.
-B block input or output using 5120 bytes per record.
-c Read or write header information as Ascii character.
-d create directories as needed.
-l link files instead of copying.
-o file direct output to a file.
-r rename files interactively.
-R ID reassign file ownership and group information to the user's login ID.
-V print a dot for each file read or written.
-s swap bytes.
-S swap half bytes.
-v print a list of filenames.
Examples
find . -name "*.old" -print | cpio -ocvB > /dev/rst8 will backup all *.old files to a tape in /dev/rst8
cpio -icdv "save"" < /dev/rst8 will restore all files whose name contain "save"
find . -depth -print | cpio -padm /mydir will move a directory tree.


Thanks,
Aneesh
Shahul
Esteemed Contributor

Re: cpio command

Hi,

I never use cpio unless I want to copy device files or special files. If you are copying normal files or directories tar is best. cpio is very slow compared to tar, I have tested this.

You already got the cpio syntax above, if needed.

Good luck
Shahul
Dennis Handly
Acclaimed Contributor

Re: cpio command

>Shahul: If you are copying normal files or directories tar is best. cpio is very slow compared to tar, I have tested this.

You can use pax(1) and create either type of files. -x cpio

(I wonder why cpio is slower? Are you using -B to set the blocksize bigger?)
Shahul
Esteemed Contributor

Re: cpio command

I used these two for huge volume of data copying.

#find . -depth -print |cpio -pmvdu /target
#tar -cvf - .|(cd /target; tar -xvf -)

I found the second one much faster than first one. I have not further analysed this, I was satisfied with tar.

Good luck
Shahul
Steve Post
Trusted Contributor

Re: cpio command

I use cpio daily. I hate tar. Of course this is my horrible, skewed opinion. It is based on experience. (good cpio ones, bad tar ones).

I have 2 gigs of data on /disk1 in directory Abc.
I want to copy it to /disk2.

If I do this, I hurt performance of the computer: cp /disk1/Abc /disk2/.

Instead I want to stream the information between the filesystems /disk1 and /disk2.

I run this:
cd /disk1
find Abc -print | cpio -pdumvc /disk2/.


I want ./Abc on a tape.
cd /disk1
find Abc -print | cpio -odumvc > /dev/rmt/0m

I want to read ./Abc from the tape to /disk2.
cd /disk2
cpio -itumvc < /dev/rmt/0m

Why do I like cpio and hate tar? 1. Mainly I just have a harder time getting the syntax correct with tar. 2. Cpio works with streamed data. Tar has to have the tar file in the command. (well it has for me anyway).
3. Cpio copies symbolic links. Tar does not. 4. cpio doesn't break when to go too many subdirectories down a directory structure. (this one is solved in later tar versions).

Things I don't like about cpio: 1. I have a hard time pulling out just one or two files from a cpio archive. It's easier to dump it all to a temp spot and then pull out the file I'm looking for.

2. I hear there are limits to the amount of data that can go through cpio. But I guess I never hit them. I always try to verify the cpio command was successful.

HOW can I verify that cpio worked?
in the case where you copy /disk1/Abc to /disk2/Abc.
cd /
dircmp -s /disk1/Abc /disk2/Abc | more

in the case where you copy /disk1/Abc to tape:

cd /disk2
cpio -idumvc < /dev/rmt/0m
cd /
dircmp -s /disk1/Abc /disk2/Abc | more

In both cases, it is assumed you have enough room to mess with junk copies of directory Abc. It's always good to have a big junk area.

One more tip. If you see "out of phase" error when reading a cpio archive: try to use the B option. try to use the c option.

Yet another tip: If your cpio command runs long and you are running it from an old ascii terminal. It might be running slow because it is display all the files being copied on the slow, ancient screen. Rerun the command with the v for verbose. You will not see anything on the screen. As a result, the computer will not be wasting its time writing to that slow terminal and instead spend its time moving files.


I hope this helps. Remember to assign points they help others get an idea if the reponse was useful or not. And zero points is a points assignment too.
Steve Post
Trusted Contributor

Re: cpio command

hey there.
You assigned 1 response out of 55?
Do you know how to use the forums?
Do you really expect an answer when you don't care to read any responses?