69

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?

1 Answer 1

140

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
1
  • 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. Commented May 9, 2020 at 4:28

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