Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

cpio exclude/include list

Status
Not open for further replies.

gotchausa

Programmer
Jan 24, 2002
64
CA
Is it possible to specify an include or exclude file list that cpio can read in order to extract certain files from tape? Lets say, these are the files on tape:

a
b
c
d

I want to use a file list called exclude_list to exclude files a and b from being copied back from tape to my unix box. Can this be done?
 
mpv:

Yes, you can do what you with cpio. Place your file names

a
b
c
d

file file_name one per line:


cpio -icvd < /dev/tape `cat file.name` # back ticks for
# command substitution

Check man cpio, because the cating the contents of a file above is actually a pattern or a regular expression. For example, suppose you want to restore everything on your tape, but file: x.file:

cpio -icvd < /dev/tape !x.file


Regards,


Ed
 
Thanks, that works.
Do you know if lets say I have several tapes and I create a file which specifies what files I need to extract from these tapes. Will cpio be smart enough to search thru each tape till all files that need to be extracted are found? Will it prompt me to insert the next tape for searching?
 
mpv:

I'm making an assumption you want to search individual cpio tapes. This is not including one cpio that spanned more than one tape. No, cpio is not smart enough to do that.

However, you could write a script to do that for you. I'm including a script that might fit your purpose. It drops into a loop, asks if there's another tape, and if you answer Y, executes the cpio command that you must include. Limitations:

1) only one cpio command is supported
2) if a file is on more than one tape, obviously it uses the last one

#!/bin/ksh

# yesorno: This function takes one argument and if the
# value is Y or y returns 1 else it returns 0. Pressing
# <CR> returns 0;
# usage: $(yesorno $answer)
function yesorno {
case $1 in
y|Y) echo 1;;
*)
echo 0;;
esac
} # end yesorno

echo &quot;Performing a cpio search&quot;
while true
do
echo &quot;Do you have another tape: Y/N: &quot;
read answer
if [ $(yesorno $answer) -eq 0 ]
then
echo &quot;terminating program&quot;
exit 1
else # place your cpio command here
echo &quot;place your cpio command here&quot;
fi
done
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top