LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   ignoring directory structure with Tar (https://www.linuxquestions.org/questions/linux-software-2/ignoring-directory-structure-with-tar-538631/)

creolophus 03-18-2007 11:34 PM

ignoring directory structure with Tar
 
Hi,

I am writing a program which needs 'tar'

The problem is that 'tar' preserves directory structure, but I dont want it to.

I need to create a simple archive with all files inside it. No directory structure.

E.g
Code:

$ pwd
dir3
$ tar -cvf foo.tar  dir1/file1 dir2/file2

the file foo.tar is structured like this
Code:

--dir3--|--dir1 -- file1
        |
        |--dir2 -- file2

but I need
Code:

--dir3 --- file1 file2

Do you know the exact options? I've search the manual, without any luck

Thank you

pixellany 03-19-2007 12:12 AM

If what you want is not in the tar manual, then maybe tar won't do this...

You may need to have some lines in your script to move the files into one directory before tarring. In pseudo-code, I'm guessing something like this:
ls -R to list all files, regardless of subdirectory
loop thru all of these, deleting the directories, and using "mv" to put them in a new directory

jlinkels 03-19-2007 06:22 AM

Check out a program called "star". It is tar-compatible, but it has a zillion options. One of them is to create tar files without directory structure (-d).

Since the intention of this option to be compatible with "tar versions which do not deal with directories", your archive might contain a flat structure, but still be compatible with tar.

You'd have to check it out yourself.

jlinkels


All times are GMT -5. The time now is 01:13 PM.