Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

Is it possible to create a target directory, similar in nature to the mkdir -p switch, where I can define a non-existent target directory within my tar command, and tar will create the directory for me?

I know I can redirct the output to a directory using tar -C /target/dir, but this doesn't work if the target directory is non-existent.

share|improve this question
2  
If it isn't possible, you could always create a shell alias. –  maxmackie Nov 25 '11 at 4:02

2 Answers 2

up vote 6 down vote accepted
mkdir -p /target/dir && tar -C /target/dir
share|improve this answer
1  
@V for V - that's what I've been using; I was thinking there might be something OOTB. –  wulfgar.pro Nov 25 '11 at 5:36

This made more sense to me mkdir -p /create/folder && tar -zxf haroopad-v0.13.0_x64.tar.gz -C /create/testfolder

mkdir makes the folder although i dont quite understand the -p switch. && lets you execute a second command. i used typical tar -switches but at the end -C is used to change directories and extract to that location needed.

reference: extract-files-contained-in-archive-tar-gz-to-new-directory-named-archive

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.