20231117在ubuntu20.04下使用ZIP命令压缩文件夹
2023/11/17 17:01
百度搜索:Ubuntu zip 压缩
https://blog.51cto.com/u_64214/7641253
Ubuntu压缩文件夹zip命令 原创
chenglei1208 2023-09-28 17:21:58博主文章分类:LINUX 小工具
文章标签命令行压缩包Ubuntu文章分类运维阅读数1554
一、安装zip命令
如果您的Ubuntu系统没有安装zip命令,可以使用以下命令进行安装:
sudo apt-get update
sudo apt-get install zip
输入密码并等待安装完成。
二、压缩单个文件夹
在命令行中,使用zip命令压缩单个文件夹非常简单。以下是基本的命令格式:
zip -r 压缩包名.zip 要压缩的文件夹路径
其中,-r参数表示递归压缩子目录。
例如,如果要将目录/home/user/documents压缩为documents.zip,可以使用以下命令:
zip -r documents.zip /home/user/documents
执行上述命令后,压缩包documents.zip将会生成在当前命令行所在目录下。
解压缩
解压目录
使用unzip命令时,可以指定解压目录。如果不指定解压目录,则默认解压到当前目录。例如,将压缩文件example.zip解压到/home/user/目录下,可以使用以下命令:
unzip example.zip -d /home/user/
三、压缩多个文件夹
如果要同时压缩多个文件夹,可以在命令行中依次指定要压缩的文件夹路径,并用空格进行分隔。例如,要同时压缩/home/user/documents和/home/user/pictures两个文件夹,可以使用以下命令:
zip -r archive.zip /home/user/documents /home/user/pictures
执行上述命令后,压缩包archive.zip将会生成在当前命令行所在目录下。
四、使用过滤器
有时候,在压缩文件夹时,您可能只需要压缩其中的部分文件或目录。Zip命令提供了一些过滤器选项,可以满足您的需求。
以下是几个常用的过滤器:
-x:排除指定的文件或目录。
-i:仅包括指定的文件或目录。
例如,要压缩目录/home/user/documents,但排除其中的/home/user/documents/cache目录,可以使用以下命令:
zip -r documents.zip /home/user/documents -x /home/user/documents/cache
执行上述命令后,压缩包documents.zip将会生成在当前命令行所在目录下,其中不包含/home/user/documents/cache目录。
五、总结
通过本篇文章,您已经学会了在Ubuntu系统中使用zip命令压缩文件夹的基本操作。如果您想了解更多zip命令的使用方法和选项,请查阅zip命令的帮助文档。
rootroot@rootroot-HP-ZHAN-66-Pro-A-14-G3:~/C101$
rootroot@rootroot-HP-ZHAN-66-Pro-A-14-G3:~/C101$ ll
total 1505032
drwxrwxr-x 3 rootroot rootroot 4096 11月 17 13:59 ./
drwxr-xr-x 29 rootroot rootroot 4096 11月 17 13:54 ../
-rw-rw-r-- 1 rootroot rootroot 770564405 11月 17 13:58 1356.tar.gz
-rw-rw-r-- 1 rootroot rootroot 770560989 11月 17 14:00 1359.tar.gz
drwxrwxr-x 26 rootroot rootroot 4096 11月 17 13:56 fastiot/
rootroot@rootroot-HP-ZHAN-66-Pro-A-14-G3:~/C101$
rootroot@rootroot-HP-ZHAN-66-Pro-A-14-G3:~/C101$
rootroot@rootroot-HP-ZHAN-66-Pro-A-14-G3:~/C101$ zip fastiot_20231117_1402.zip fastiot/
rootroot@rootroot-HP-ZHAN-66-Pro-A-14-G3:~/C101$
rootroot@rootroot-HP-ZHAN-66-Pro-A-14-G3:~/C101$ ll
total 1505032
drwxrwxr-x 3 rootroot rootroot 4096 11月 17 13:59 ./
drwxr-xr-x 29 rootroot rootroot 4096 11月 17 13:54 ../
-rw-rw-r-- 1 rootroot rootroot 770564405 11月 17 13:58 1356.tar.gz
-rw-rw-r-- 1 rootroot rootroot 770560989 11月 17 14:00 1359.tar.gz
drwxrwxr-x 26 rootroot rootroot 4096 11月 17 13:56 fastiot/
rootroot@rootroot-HP-ZHAN-66-Pro-A-14-G3:~/C101$
rootroot@rootroot-HP-ZHAN-66-Pro-A-14-G3:~/C101$
rootroot@rootroot-HP-ZHAN-66-Pro-A-14-G3:~/C101$ zip fastiot_20231117_1402.zip fastiot/
adding: fastiot/ (stored 0%)
rootroot@rootroot-HP-ZHAN-66-Pro-A-14-G3:~/C101$
rootroot@rootroot-HP-ZHAN-66-Pro-A-14-G3:~/C101$ zip -r fastiot_20231117_1403.zip fastiot/
adding: fastiot/ConfigManagerNode/inc/Config_key.h (deflated 67%)
adding: fastiot/ConfigManagerNode/inc/capabilityManager.h (deflated 53%)
adding: fastiot/ConfigManagerNode/src/ (stored 0%)
adding: fastiot/ConfigManagerNode/src/configManager.cpp (deflated 88%)
adding: fastiot/ConfigManagerNode/src/Makefile (deflated 52%)
adding: fastiot/ConfigManagerNode/src/capabilityManager.cpp (deflated 74%)
adding: fastiot/ConfigManagerNode/src/Config_get.cpp (deflated 77%)
adding: fastiot/DataEngine/ (stored 0%)
adding: fastiot/DataEngine/inc/ (stored 0%)
adding: fastiot/DataEngine/inc/TalkCollector.h (deflated 45%)
adding: fastiot/DataEngine/inc/BatteryCollector.h (deflated 43%)
adding: fastiot/DataEngine/inc/MonitorCollector.h (deflated 45%)
adding: fastiot/DataEngine/inc/Upgrade_Processor.h (deflated 43%)
adding: fastiot/DataEngine/inc/Cloud_Processor.h (deflated 47%)
adding: fastiot/DataEngine/inc/SDLog_Processor.h (deflated 43%)
adding: fastiot/DataEngine/inc/Rtsp_Processor.h (deflated 45%)
adding: fastiot/DataEngine/inc/S3Client_Processor.h (deflated 48%)
adding: fastiot/DataEngine/inc/IOCtrl_Collector.h (deflated 45%)
adding: fastiot/DataEngine/inc/Cgi_Processor.h (deflated 38%)
adding: fastiot/DataEngine/inc/FactoryCollector.h (deflated 46%)
adding: fastiot/DataEngine/inc/Config_Collector.h (deflated 43%)
adding: fastiot/DataEngine/inc/VideoProducer.h (deflated 36%)
adding: fastiot/DataEngine/inc/list.h (deflated 80%)
adding: fastiot/DataEngine/inc/SDCardRecord_Processor.h (deflated 48%)
adding: fastiot/DataEngine/inc/AudioProducer.h (deflated 37%)
adding: fastiot/DataEngine/inc/ReverVideo_Collector.h (deflated 47%)
adding: fastiot/DataEngine/inc/MsgCore.h (deflated 67%)
adding: fastiot/DataEngine/src/ (stored 0%)
adding: fastiot/DataEngine/src/MsgCoreControlServer.cpp (deflated 71%)
adding: fastiot/DataEngine/src/Config_Collector.cpp (deflated 81%)
adding: fastiot/DataEngine/src/MsgCoreControlClient.cpp (deflated 74%)
adding: fastiot/DataEngine/src/AudioProducer.cpp (deflated 74%)
adding: fastiot/DataEngine/src/ReverVideo_Collector.cpp (deflated 77%)
adding: fastiot/DataEngine/src/SDCardRecord_Processor.cpp (deflated 79%)
adding: fastiot/DataEngine/src/SDLog_Processor.cpp (deflated 72%)
adding: fastiot/DataEngine/src/Upgrade_Processor.cpp (deflated 71%)
adding: fastiot/DataEngine/src/Cloud_Processor.cpp (deflated 73%)
adding: fastiot/DataEngine/src/Makefile (deflated 61%)
adding: fastiot/DataEngine/src/BatteryCollector.cpp (deflated 73%)
adding: fastiot/DataEngine/src/MonitorCollector.cpp (deflated 75%)
adding: fastiot/DataEngine/src/FactoryCollector.cpp (deflated 76%)
adding: fastiot/DataEngine/src/Cgi_Processor.cpp (deflated 71%)
adding: fastiot/DataEngine/src/S3Client_Processor.cpp (deflated 72%)
adding: fastiot/DataEngine/src/VideoProducer.cpp (deflated 77%)
adding: fastiot/DataEngine/src/MsgCoreServ.cpp (deflated 80%)
adding: fastiot/DataEngine/src/IOCtrl_Collector.cpp (deflated 74%)
adding: fastiot/DataEngine/src/TalkCollector.cpp (deflated 77%)
adding: fastiot/DataEngine/src/Rtsp_Processor.cpp (deflated 70%)
rootroot@rootroot-HP-ZHAN-66-Pro-A-14-G3:~/C101$
rootroot@rootroot-HP-ZHAN-66-Pro-A-14-G3:~/C101$ ll
total 2292296
drwxrwxr-x 3 rootroot rootroot 4096 11月 17 14:04 ./
drwxr-xr-x 29 rootroot rootroot 4096 11月 17 13:54 ../
-rw-rw-r-- 1 rootroot rootroot 770564405 11月 17 13:58 1356.tar.gz
-rw-rw-r-- 1 rootroot rootroot 770560989 11月 17 14:00 1359.tar.gz
drwxrwxr-x 26 rootroot rootroot 4096 11月 17 13:56 fastiot/
-rw-rw-r-- 1 rootroot rootroot 166 11月 17 14:02 fastiot_20231117_1402.zip
-rw-rw-r-- 1 rootroot rootroot 806147076 11月 17 14:04 fastiot_20231117_1403.zip
rootroot@rootroot-HP-ZHAN-66-Pro-A-14-G3:~/C101$
rootroot@rootroot-HP-ZHAN-66-Pro-A-14-G3:~/C101$