63

As titled. I want to use some command, like for .zip files I can say

unzip myfiles.zip -d mydirectory

But is there a thing for .tar file on Mac as well?

Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
nekodesu
  • 789
  • 1
  • 7
  • 10

1 Answers1

124

Yes, you can run:

tar -xvf myfile.tar

For .tar.gz, you can run:

tar -xzvf myfile.tar.gz

If you want to extract to any directory other than your cwd, use -C. e.g:

tar -xvf myfile.tar -C somedirectory

I suggest you read the man page for tar if you wish to do anything further:

man tar
Hayley
  • 2,977
  • 3
  • 18
  • 16
  • One option that I'll point out since it may be common is the ability to strip parent directories with `--strip=1`. If you need to "flatten" out the extracted files to aid with automation, play with this and see if it will help. – Joshua Pinter May 09 '20 at 04:28