I have to compress multiple files to one tar-File. As I have to repeat this for many files in many different folders I wrote a shell script and started it from a parent directory. The shell script contains multiple lines like the following:
tar -cf a/b/c/tarfile.tar a/b/c/*
This creates a tar-file in the specified folder but inside the tar-File the folder structure of a/b/c/ is still existent.
What I want is that all files in c/ are placed in tarfile.tar WITHOUT the folder structure a/b/c/. Is this possible?
tar -cf a/b/c/tarfile.tar -C a/b/c .
will switch to the directory a/b/c
and read in the entire directory (the .
- you could specify specific files as well, but a wildcard will not do what you're expecting). The -C <directory> <filelist>
pattern can be repeated as necessary to process additional files from different locations.
Another possibility given your original example would be cd a/b/c; tar cf ../../../tarfile.tar *
, but that doesn't give you the possibility to pull multiple files from different locations (of course you could still use -C
, but the relative paths would have to be adjusted accordingly.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With