0

I have the following directory structure:

A0
├── A1
│   ├── A1_B1
│   │   ├── A1_B1_1.docx
│   │   ├── A1_B2_2.pptx
│   ├── A1_B2
│   │   └── A1_B2_C1
│   │       ├── A1_B2_C1_D1
│   │       │   ├── A1_B2_C1_D1_1.docx
│   │       │   └── A1_B2_C1_D1_2.docx
│   │       └── A1_B2_C1.xlsx
├── A2
└── A0.txt

I want to create a .7z file that will contain only the files. I don't want to keep the folders. I have tried this answer and this answer but they don't work in Linux.
Is it possible to do it with 7z or I should extract files to a single directory first and then compress.

Ani
  • 159
  • 7
  • Could you please show us the command you've tried? – 0stone0 Jun 22 '21 at 16:15
  • 1
    [so] is for programming questions, not questions about using or configuring Unix and its utilities. [unix.se] or [su] would be better places for questions like this. – Barmar Jun 22 '21 at 16:23
  • If you have two files named the same way in two different paths, you will have trouble with that approach. – kikito Jun 22 '21 at 16:24
  • I have tried a few things: 1. `7z a A0.7z /u/anipet/Desktop/A0/*` 2. `7z a -tzip A0.zip /u/anipet/Desktop/A0/*` 3. `7z a -tzip -r A0.zip ./A0/*`, etc. – Ani Jun 22 '21 at 16:25
  • @kikito Yes, I am aware of that. All the files have unique names. – Ani Jun 22 '21 at 16:29

1 Answers1

0

If for some reason the answers you reference to don't work try this instead.

Create a directory

mkdir flat_dir

Link all files from the desired folder recursively in flat_dir, for me the desired folder was cpptest.

for full_path_file in $(find ../cpptest -type f)
do
echo "$full_path_file"
filename=$(echo "$full_path_file" | rev | cut -d '/' -f 1 | rev)
echo "$filename"
ln -s -T "$full_path_file" "$filename"
done

Zip the files

7z a test.zip -l ~/flat_dir