0

i want to tar the contents inside /some/directory/ and this directory has lots of files and other sub directories in it.

what is the actual difference between the below tar commands, i noticed the latter command contains more files in the tar archive compared to the first one.

i compared by using tar -tvf | wc -l on each archive

cd /some/directory/
tar -cvf /tmp/directory.tar *

compared to

tar -cvf /tmp/directory.tar -C /some/directory/ .
1
  • 1
    If I get it right * is not including files starting with a dot like .bashrc while . is including all files in the directory.
    – Michael D.
    Commented Jun 16, 2020 at 0:08

1 Answer 1

1

The first command will tar all files inside /some/directory recursively where the pattern * matches. These are generally all non-hidden files. If you're using bash, you need to enable the dotglob shell option with shopt -s dotglob to also match hidden files before running the command.

The second command changes the directory to /some/directory and includes the current directory . and all files including hidden files inside it. It also adds ./ as parent directory to the archive. You can see this additional folder with tar tf /tmp/directory.tar, but there is no difference to the first command on extraction (besides missing hidden files and that all files in the second archive are prefixed with the relative path ./)

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .