Compress Each Folder With One Archive if Archive Is Not Exist
The provided command is a shell script written in Bash that iterates through directories in the current directory, checks if an archive file (.tar.gz) already exists for each directory, and if not, it creates a compressed archive of the directory using the tar
command.
Here’s an explanation of what the script does:
|
|
-
for dir in
find . -maxdepth 1 -type d | grep -v “^.$”; do
: This line starts a loop that iterates through all subdirectories (excluding the current directory) in the current directory. -
if ! [ -e ${dir}.tar.gz ] ; then
: This line checks if an archive file with the name${dir}.tar.gz
does not exist in the current directory. -
Inside the
if
block,tar -cvzf ${dir}.tar.gz ${dir}
creates a compressed archive of the current directory (${dir}
) with the name${dir}.tar.gz
. Here’s what the options used with thetar
command do:-c
: Create a new archive.-v
: Verbosely list the files processed.-z
: Compress the archive using gzip.-f
: Specifies the archive file’s name.
-
The
done
keyword marks the end of the loop.
So, this script essentially compresses each subdirectory in the current directory into a .tar.gz
archive file if such an archive does not already exist for that subdirectory.
If you have any specific questions or need further assistance with this script, please let me know.