Monday, April 4, 2022

[SOLVED] How to compress multiple folders with certain name?

Issue

I have the following folder,

   (Project) [Usr@hpc FOB]$ ls
    exec_train.sh          FOB_RE2250_BS4ES025.py                 network_checkpoint_FOB_RE2250_BS2ES05
    FOB_RE1150.py          FOB_RE2250_BS4ES05.py                  network_checkpoint_FOB_RE2250_BS2ES1
    FOB_RE1200.py          FOB_RE2250_BS4ES1.py                   network_checkpoint_FOB_RE2250_BS4ES025
    FOB_RE2250_BS05ES1.py  FOB_RE2250.py                          network_checkpoint_FOB_RE2250_BS4ES05
    FOB_RE2250_BS05ES2.py  FOB_RE50.py                            network_checkpoint_FOB_RE2250_BS4ES1
    FOB_RE2250_BS1ES1.py   network_checkpoint_FOB_RE2250_BS05ES1  
    FOB_RE2250_BS2ES05.py  network_checkpoint_FOB_RE2250_BS05ES2 
    FOB_RE2250_BS2ES1.py   network_checkpoint_FOB_RE2250_BS1ES1

How do I compress the all the network_checkpoint_FOB.... into one .tar.gz archive?

I know I could manually use $ tar -czf FOB.tar.gz network_checkpoint_FOB_RE2250_BS1ES1 network_checkpoint_FOB_RE2250_BS05ES1 ... but this seams cumbersome. I think there should be a way to use string matching but I haven't been able to find a clear concise solution.


Solution

You can use wildcard character * in Bash:

$ tar -czf FOB.tar.gz network_checkpoint_FOB*

Bash automatically expands network_checkpoint_FOB* expression to space separated matching file/folder names.



Answered By - C. Aknesil
Answer Checked By - Mildred Charles (WPSolving Admin)