With a similar command, the full path is packed.

tar -cvpf test.tar.gz mypc/test/testdir 

it packs the entire mypc/test/testdir

I need to archive a specific folder in another folder so that the root folder does not fall into the archive, and only test/testdir , can anyone know the command? Searched in manuals did not find.

    2 answers 2

    you can use the option -C каталог , meaning "during the creation of the archive to make the specified directory current."

    i.e., instead of

     $ tar -cvpf test.tar.gz mypc/test/testdir 

    use the following command:

     $ tar -cvpf test.tar.gz -C mypc test/testdir 

    do not worry about the location of the file specified by the -f файл option - it will be created where the command is run from.

      You can try to first go to the directory you need, like this:

       cd ./mypc && tar -cvpf test.tar.gz ./test/testdir && cd - 

      And by the way, in order to get a compressed archive ( .gz ), you need to add the -z key to ( .gz ) to -cvpf .

      • one
        There is an option -C - mymedia