SHELL command to ZIP only subfolders where folder name > 6000 - shell

I have a folder named images with 7000 subfolders in it named 1, 2, 3... until 7000.
I need to zip only the folders where folder name > 6000.
Is this possible?
I was trying to exclude folders like:
zip -r myarchive.zip dir1 -x dir1/ignoreDir1/**\* dir1/ignoreDir2/**\*
but this is too long to perform with 7000 folders.

Instead of excluding, select only the ones you need. You can use the single character wildcard ? to select subfolder names with specific length:
zip -r archive.zip images/6???/* images/7???/*
This will add all files to the archive from images/6000/* to images/7999/*

Related

How do I unzip a specific folder within a zipped file, and exclude some specific folder within it?

I have a zipped file:
main.zip
And I want to unzip only some folders present in the zipped folder while excluding the .git pack file.
The folder structure in main.zip is as follows:
main.zip -> main_folder -> folder1, folder2... and I want to extract only folder2 from the zipped file, but this folder2 contains the .git folder with packed files, which I don't need.
So far I have tried :
unzip main.zip "main_folder/folder2/*" -d ~ path/to/some/directory
!(*.git) will exclude the files ending with .git, but how do I integrate this in the command above?
The exclude option works!
We just need to provide a path to the files to be excluded!
unzip main.zip "main_folder/folder2/*" -x "main_folder/folder2/*.git/*" -d path/to/some/directory

how to rename two files to different name automatically in bash

I have a problem that I want to know how to do it automatically in bash:
I have 12 folders(0,1,2,3..11), each contain two files like shown below, for example, in folder 1, it contains:
4DNFI6E4RZ9H.fastq.gz
4DNFIIN1NES7.fastq.gz
and none of the files in the folders share the same name.
I want to create a script that can loop into each of the folders, and rename the files according to the name of the folders, for example for files in folder 1, I want the two files to be renamed to:
1_R1.fastq.gz
1_R2.fastq.gz
for files in folder 2, I want the two files to be renamed to:
2_R1.fastq.gz
2_R2.fastq.gz
...
So how to do it? thanks a lot!
Like this :
#!/bin/bash
for dir in */; do
c=0
for file in $dir/*; do
mv "$file" "${file%/}_R$((++c)).fastq.gz"
done
done
ls *

How to extract all files at once in folders from a tar.gz file

I have a tar.gz file which includes 2 tar files and each tar file includes several folders and subfolders that include my required files.
I want to extract the final files from those subfolders in a directory.
I know I can use something like tar -xzvf but finally, it gives me all the folders and subfolders and the files I needed in those subfolders.
Example file:
file.tar.gz: this file contains 1.tar and 2.tar. 1.tar contains folder1, folder2, ..., folder100. and 2.tar contains foldera, folderb, ..., folderz. My text files are in these subfolders.
I want to extract all of my text files in a user-defined directory without extracting subfolders. my_dir/*.txt
Any help would be much appreciated.
Thank you.

Delete folders and files from many subfolders

I have this structure - main folder with many subfolders (names for example only):
Mainfolder
|-subfoldernamea
|-subfoldernameb
|...
|-subfoldernamez
each subfolder have folders and files.
I need to delete folders and files (older than 1 month) in each subfolder.
It is possible to create simple cmd script, or i need manually write all subfolders names in script?

bash zip omit files

I'd like to zip a folder, but zip skips files.
Folder structure is:
main_folder > sub_folder > file2.sql
file11.txt
file12.sql
Main_folder contains sub_folder and two files, subfolder contains one file.
When i use
zip -r $path *
i receive .zip file which contains everything except file11.txt. I tried various options but have not solved the problem. Zip makes correct structure and takes every single file except files from main_folder.
could you try this;
zip -r your.zip * -x file11.txt
man zip;
-x files
--exclude files
Explicitly exclude the specified files..

Resources