mirror of https://github.com/tLDP/LDP
34 lines
699 B
Bash
34 lines
699 B
Bash
#!/bin/bash
|
|
|
|
# Copying a directory tree using 'cpio.'
|
|
|
|
# Advantages of using 'cpio':
|
|
# Speed of copying. It's faster than 'tar' with pipes.
|
|
# Well suited for copying special files (named pipes, etc.)
|
|
#+ that 'cp' may choke on.
|
|
|
|
ARGS=2
|
|
E_BADARGS=65
|
|
|
|
if [ $# -ne "$ARGS" ]
|
|
then
|
|
echo "Usage: `basename $0` source destination"
|
|
exit $E_BADARGS
|
|
fi
|
|
|
|
source=$1
|
|
destination=$2
|
|
|
|
find "$source" -depth | cpio -admvp "$destination"
|
|
# ^^^^^ ^^^^^
|
|
# Read the 'find' and 'cpio' man page to decipher these options.
|
|
|
|
|
|
# Exercise:
|
|
# --------
|
|
|
|
# Add code to check the exit status ($?) of the 'find | cpio' pipe
|
|
#+ and output appropriate error messages if anything went wrong.
|
|
|
|
exit 0
|