tar compresses folder, but creates nested structure

You can try following:

tar -czf ./zips/someFile.tar.gz -C ./tmp/ someFolder

You can use the parameter -C or --directory

tar -czf ./zips/someFile.tar.gz -C ./tmp someFolder

From man tar

-C, --directory DIR
      change to directory DIR

Example

% ls -og
total 4
-rw-rw-r-- 1    0 Mai 21 18:39 bar
drwxrwxr-x 2 4096 Mai 21 18:39 foo

tar -cvf ../sample.tar -C /home/user/tmp .

tar -tvf ../sample.tar 
drwxrwxr-x user/user 0 2015-05-21 18:39 ./
-rw-rw-r-- user/user 0 2015-05-21 18:39 ./bar
drwxrwxr-x user/user 0 2015-05-21 18:39 ./foo/

The tar command does not zip. Not even with the -z flag. However, it does collect a series of files/folders and optionally compress the result. To contrast, zip compresses each file and adds it to an archive. zip and tar use different compression algorithms.

The man page for GNU tar shows the -C flag (--directory) to change directory, so you could do this

tar czfC zips/someFile.tar.gz tmp someFolder

You could also use the --transform option to remove the leading tmp/

tar czf zips/someFile.tar --transform 's#^tmp/##' tmp/someFolder

Tags:

Directory

Tar