Tar doesen't extract with -P flag - tar

I have an archive named compressed.tar.gz
I want to exract its contents to the folder uncompressed, located in the same directory.
In terminal:
tar -xf compressed.tar.gz -C uncompressed
This works and extracts correctly, however I get an stderror: "Removing leading "/" from member names". I've running above command using -P to suppress the error message as so:
tar -Pxf compressed.tar.gz -C uncompressed
Although the contents are not being extracted at all to uncompressed folder. Any ideas would be greatly appreciated.

Related

How to get path of directory in gunzip bundle

My gunzip structure is like something like this
archive.tgz/manager-34038240834402384/temp1
/temp2/temp4/temp5
/temp3/temp6
I just need the string 'manager-34038240834402384' without extracting whole bundle. How to get it?
I tried tar -tvf which gives me whole path, but I just want above string. How to get it?
tar --list -f archive.tgz | head -n 1

tar excluding parent directories and creating tarball on remote host

I have a host where an application creates model directories/files. I want to tar up those files and send it over to another host for DR backup.
So far I have the following:
sudo tar -zcvf - /mnt/nfsshared | ssh app#<ip-address> "cat > /data/models/models_$(date +\%Y-\%m-\%d).tar.gz" > /dev/null 2>&1
This command will tar up all directories and files in /mnt/nfsshared and create the tarball on the remote host under /data/models/
However, I want to exclude the the /mnt/nfsshared/ parent directories and just tar up the directories/files in the /nfsshared directory.
I know I could cd to /mnt/nfshared and tar up all files.
I can also do this command
sudo -C /mnt/nfsshared -zcvf | ssh app#<ip-address> "cat > /data/models/models_$(date +\%Y-\%m-\%d).tar.gz" > /dev/null 2>&1
which would only tar up directories/files under nfsshared. However, what argument would I pass to the command: -zcvf
I can't use a tarball name since the tarball gets created on the remote host.
Within /mnt/nfsshared/ I have multiple directories containing additional subdirectories and files.
/mnt/nfsshared/model1/files
/model2/files
/model3/submodel1/files
/submodel2/files
/submodel3/files
/model4/submodel1/files
I want only to tar up the model, submodel directories and the files I want to exclude the /mnt/nfsshared directories
Cheers,
Roland

How to untar without leading slash /

I have tar file, 11.2.0.4.tar, of the following path: /oracle/product/11.2.0.4. I want to untar it in a custom folder, for example /export. I tried with the -C option, but didn't work - the shell hangs for a few seconds, then the prompt is returned without any result.
tar -xvf 11.2.0.4.tar -C /export
So, how do I extract without the "/" so I would have /export/oracle/product/11.2.0.4? I read there is an option only when taring, but not when untaring.

Copy list of files with tar command. Bash

I have the directory A/a A/b where both a and b are files.
When I run these commands I get the outputs.
-> tar --include A -v -cf A.tar A
a A
a A/a
a A/b
-> tar --include A/a -v -cf A.tar A
I don`t understand in the 2nd evocation why file A/a is not archived. I believe I do not understand how include works.
I am trying to give tar a list and have it create an archive with the contents. Please help.
Thank you.

tar all files to a directory

The following will extract the files in /root/ directory. But it also creates the parent directories under root. What I need is that the files should be exactly under root folder and not in /root/data/mysql/...
# tar -xvf company_raw_2012-02-22.tgz --directory=/root/
data/mysql/company_raw/data_archive_r_20120222.MYD
data/mysql/company_raw/data_archive_r_20120222.MYI
data/mysql/company_raw/data_archive_r_20120222.frm
If that is not possible, how do I write a program to move these files to the required folder?
I have tried the following and it does work.
--strip-components=3
But I do not know how many folder will be there. So the number 3 may change.
Extract everything to the temp directory with full path and then just walk it moving files to the desired destination?
destdir=/root
tmpdir=/root/tmp
rm -rf $tmpdir
mkdir $tmpdir
tar xf archive.tar.gz -C $tmpdir
find -H $tmpdir -type f -exec mv '{}' $destdir \;

Resources