This question already has an answer here:

I would like to be able to tar all of my files so that when the are extracted they're in a sub directory I have specified. For example if I have File1 File2 and File3 inside of my current directory I would like to run a tar -jcvf files.tbz2 ./* in a way that when they extract they extract into files/File1 files/File2 files/File3 without having to create that directory.

marked as duplicate by Zoredache, Michael Hampton, DerfK, Iain Mar 28 '13 at 17:25

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • Your question is off topic for Serverfault because it doesn't appear to relate to servers/networking or desktop infrastructure in a professional environment. It may be on topic for Unix.SE but please search their site for similar questions that may already have the answer you're looking for. – Dennis Kaarsemaker Mar 28 '13 at 16:46
  • Alright, I was directed here thinking it was good for admin tasks. I'll look somewhere else. – Lethjakman Mar 28 '13 at 16:50
  • If you ask it on the unix site I'll answer it there :) – Dennis Kaarsemaker Mar 28 '13 at 16:51
  • 1
    @DennisKaarsemaker: Why isn't this an admin task ? ( a simple one admitedly). – Iain Mar 28 '13 at 16:52
  • 1
    @Iain to be honest: I was just being polite and would answer on unix. I really think the question should be closed as nonconstructive, as even a cursory read of the manpage (which is minimal research) would have revealed the answer. My impression is that serverfault requires askers to perform this minimal research itself, where on unix.se such beginner questions without own research are better tolerated. – Dennis Kaarsemaker Mar 28 '13 at 16:57

try the -C switch.

tar -zxvf foo.tar.gz -C relative/subdir

tar -zxvf foo.tar.gz -C /home/user/absolute/subdir
  • I'm looking for a command that would look more like tar -jcvf ./foo.tar.bz2 ./* – Lethjakman Apr 3 '13 at 18:33

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