If you want to zip a file or a directory while being on a Bash Shell on Terminal, you can make use of the zip command.
Before taking a look at how to use this command, make sure that the zip package is available on your OS - Ubuntu/macOS/Linux. It is common that it is not available if you use an image on Docker Container.
# zip
bash: zip: command not found
Installing zip package:
# apt install zip
....
Preparing to unpack .../unzip_6.0-26ubuntu3.1_arm64.deb ...
Unpacking unzip (6.0-26ubuntu3.1) ...
Selecting previously unselected package zip.
Preparing to unpack .../zip_3.0-12build2_arm64.deb ...
Unpacking zip (3.0-12build2) ...
Setting up unzip (6.0-26ubuntu3.1) ...
Setting up zip (3.0-12build2) ...
Now let's try to zip a file.
# zip data.zip data.txt
adding: data.txt (deflated 13%)

Now let's try to zip a directory. Make sure to add -r flag to zip files within the directory recursively.
# zip -r all_reports.zip reports/
updating: reports/ (stored 0%)
adding: reports/report_2023.csv (deflated 36%)
adding: reports/report_2022.csv (deflated 54%)
adding: reports/report_2021.csv (deflated 55%)

Provide Feedback For This Article
We take your feedback seriously and use it to improve our content. Thank you for helping us serve you better!
😊 Thanks for your time, your feedback has been registered!
Comments & Discussion
Facing issues? Have questions? Post them here! We're happy to help!