0

I (regularly) have an archive with 10 or so folders in there, each containing 1 or 2 files. I want all of those files, but just in 1 folder, not in 10. Extracting the archive gives me 10 folders and means I have to manually go into each folder to cut and paste the files out of each folder. Is there a way to extract all the files out of all the folders ?

Both Archive Manager and Xarchiver keep the directories and I can't find a way to change that. Nor did I find my answer on google, maybe because I don't know how to easily describe it.

2
  • It probably depends on what kind of archives they are and what utility the archive manager uses under the hood - for example, GNU tar provides a --strip-components option. Commented Jun 20, 2018 at 19:02
  • Do you know what kind of archive it is? Can you decide what kind of archive to create, for example a tar archive tarfile or compressed tar archive tarfile.gz?
    – sudodus
    Commented Jun 20, 2018 at 20:03

1 Answer 1

1

You can do it with tar

The following command line works for me (I tested it with two levels of subdirectories).

tar -xv --transform='s#.*/##' -f tarfile

Directories will also be extracted to the top level; I hope you can cope with that.

Test example

Directory to 'put into a tarfile'

$ find
.
./1
./1/hello
./1/3
./1/3/gday
./hej
./2
./2/4
./2/4/bye
./2/hi

tar -cvf ../tarfile .

Extract from the tarfile

$ tar -xv --transform='s#.*/##' -f ../tarfile
./
./1/
./1/hello
./1/3/
./1/3/gday
./hej
./2/
./2/4/
./2/4/bye
./2/hi

List files

$ ls -1
1
2
3
4
bye
gday
hej
hello
hi

If you create the tarfile you can strip/transform the file names when you create the tarfile (and need not do it when you extract the files).

tar -cv --transform='s#.*/##' -f ../tarfile .

$ tar -xvf ../tarfile
./
1/
hello
3/
gday
hej
2/
4/
bye
hi

$ ls -1
1
2
3
4
bye
gday
hej
hello
hi

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .