tar cvf /var/lib/backup/sample.tar /home/user/.projectHowever, when I extract, I get its parents as well/backup/  - /home/     - /user/        - .project/This tar commands does it job because it doesn't include anything else in its parents (other folders under user for example).I want to do this programmatically, so changing the current working directory into /home/user/ is not really an option. Is it possible to do that?
I want to tar X directory not including its parents
directory;tar
You can either use the -C option to change into the /home/user directory before tarring or use --strip-components 2 on extraction.tar cvfC /var/lib/backup/sample.tar /home/user .project#                              Note the space ^tar cvf /var/lib/backup/sample.tar /home/user/.projecttar Cxf /backup /var/lib/backup/sample.tar --strip-components 2