LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Blogs > ciotog
User Name
Password

Notices


Rate this Entry

Copy directory using tar

Posted 03-03-2009 at 10:04 AM by ciotog
Updated 03-07-2009 at 08:40 AM by ciotog (remove stray echo, no need to test before mkdir when using -p)

Here's a simple script that uses tar to copy a directory. Naturally it would need to be called cpdir (or alter the usage method) and present in your path to use it.

Code:
#!/bin/sh

usage()
{
	cat << USAGE
	usage: cpdir <source-dir> <dest-dir>
USAGE
}

if [ -z "$1" -o -z "$2" -o ! -d "$1" -o -e "$2" -a ! -d "$2" ]
then
	usage
	exit 1
fi

# Make the target dir if it doesn't already exist
mkdir -p $2

# Do the copy using tar
tar -C $1 -c -z -f - . | tar -C $2 -x -z -f -
Posted in scripts
Views 4563 Comments 0
« Prev     Main     Next »
Total Comments 0

Comments

 

  



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

Main Menu
Advertisement
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