Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and beginning April 20th, 2021 (Eastern Time) the Yahoo Answers website will be in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.

In linux using TAR, why do you need C when Extracting, but you do not when compressing?

for example:

Compressing

tar -cvf $HOME/etc.backup.tar /tmp/data

There is no -C needed

Extracting

tar -xvf $HOME/etc.backup.tar -C /tmp/data/

Notice how you need the -C in between.

What is the logical process behind this? Also, why does the input location in the command line changes from right to left when compressing, meaning: tar -cvf $HOME/etc.backup.tar /tmp/data ........ the /tmp/data, the second location in the command line is the input and $HOME/etc.backup.tar , the first input is the output.... then when extracting it is vice versa?

1 Answer

Relevance
  • 2 years ago

    You're completely wrong, on all counts. First, when compressing, -C is a valid option. It is used to add files or from another directory to the archive. For example

    tar -cvf $/HOME/etc.backup.tar /tmp/data -C /etc passwd

    Second, when extracting, -C is only used if you want to extract it in a directory other than the current working directory. The following:

    tar -xvf $HOME/etc.backup.tar

    will extract the contents of the tar file in the current working directory.

    The input and output being reversed is common sense, since extracting is the opposite of compressing. You must be really bad at parking.

Still have questions? Get your answers by asking now.