Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

tar file preserves full path. how to stop it?

Tags:

php

tar

I am trying to create a tar archive on my server through PHP as follows:

exec('tar -cvf myfile.tar tmp_folder/innerfolder/');

It works fine, but the saved file preserves the full path including tmp_folder/innerfolder/ I am creating those on the fly for users, so it's a bit unusable for users to have this path while extracting. I have reviewed this topic - How to strip path while archiving with TAR , but in the explanation the guy doesn't give an example, and I don't quite understand what to do.

Please, tell me with an example, how to add files to tar in a way that it does not preserve the 'tmp_folder/innerfolder/' part in archive?

Thanks in advance

like image 877
Timur Gafforov Avatar asked Jan 23 '26 18:01

Timur Gafforov


1 Answers

Use the -C option to tar:

tar -C tmp_folder/innerfolder -cvf myfile.tar .

Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!