0

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.

shantanuo
  • 31,689
  • 78
  • 245
  • 403

1 Answers1

2

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 \;
rkhayrov
  • 10,040
  • 2
  • 35
  • 40