User forums > General (but related to Code::Blocks)

Quite off topic

<< < (2/2)

takeshimiya:
Ok, ok, a simply looking at tar --help I found the cause, tar (in Windows at least) doesn't support a directory parameter to -f.  :D

You must specify always FILES only with -f (--file), not DIRECTORIES.
You must specify the origin DIRECTORY with -C (--directory).

This will do the trick:

--- Code: ---D:\desktop\SomeFolder>tar -cf a.tar -C D:/desktop/SomeFolder a.txt
--- End code ---

However, it is also bad,

The correct way is enclosing with quotes all directories and files, because the filenames/directories can contain spaces:

--- Code: ---D:\desktop\SomeFolder>tar -cf "a.tar" -C "D:/desktop/SomeFolder" "a.txt"
--- End code ---

I think that always it's recommended to enclose with quotes the filenames/directories when passing as a parameter to any program.

That's it :)

takeshimiya:
For more information, refer to the help of tar,

ie. the help says that you can do something like this:

--- Code: ---example% cd fromdir; tar cf - .| (cd todir; tar xfBp -)
--- End code ---

http://www.computerhope.com/unix/utar.htm
http://www.gnu.org/software/tar/manual/html_mono/tar.html

thomas:
Takeshimiya, this helped a lot, thank you :)
Hard to believe I've been using tar wrong ever since, lol. Funny enough, it works on Linux just the way I expected it to.

It is almost perfect now like this:
  export repo to %SYSTEMTEMP%/SomeTempFolder
  cd to desired location of archive
  tar -cf archivename.tar -C %SYSTEMTEMP%/SomeTempFolder .

The only issue that remains is that tar puts everything into a folder "." inside the tar archive which is a little unpleasing. Luckily, this does not matter much, as the archives unpack fine. Sure one could work around that, but I guess I'll leave it. None of the compression utilities that I have tried seems to have a problem with it.

grv575:
Odd, but I guess . is a directory.

Wouldn't

tar -cf archivename.tar -C %SYSTEMTEMP%/SomeTempFolder *

work?

thomas:

--- Quote from: grv575 on August 10, 2005, 08:46:43 pm ---Odd, but I guess . is a directory.

Wouldn't

tar -cf archivename.tar -C %SYSTEMTEMP%/SomeTempFolder *

work?

--- End quote ---
No because * will be expanded to all files in your CWD, not to all files in the directory given with -C.

EDIT: Funnily, that was my first thought, too, but it is obviously wrong if you think about it. Unluckily, tar does no shell expansion of its own, so "*" will not work either - tar will complain "no such file: *".

Navigation

[0] Message Index

[*] Previous page

Go to full version