linux文件压缩和解压缩操作
linux文件压缩和解压缩操作
经常传文件到服务器时,可能会碰到ftp传输大量的小文件感觉速度很慢,如果我们把需要上传的文件在本地压缩成一个zip文件,然后上传到服务器,再通过ssh连接到服务器,直接在服务器上执行解压缩,这样整体效率非常高,一个2M的test程序,从上传压缩文件到展开只用了45秒。” 关于windows下使用winrar就可以把文件夹压缩成zip文件,方法是【右键预压缩的文件夹】–>【弹出快捷菜单】–>【添加到压缩文件…】–>打开【压缩文件和参数】常规选项卡在压缩文件格式选中ZIP,然后按确定就ok了
unzip解压zip文件
[root@localhost html]# ls ← 列出当前目录下的文件和文件夹 blog index.html phpinfo.php yjh.zip [root@localhost html]# unzip yjh.zip ← 解压zip文件 Archive: yjh.zip creating: yjh/ inflating: yjh/20080506056.jpg inflating: yjh/20080506057.jpg inflating: yjh/20080506064.jpg inflating: yjh/20080506065.jpg inflating: yjh/20080506066.jpg inflating: yjh/Thumbs.db inflating: yjh/20080506068.jpg inflating: yjh/20080506071.jpg inflating: yjh/20080506063.jpg inflating: yjh/olympics-2008-2.jpg inflating: yjh/olympics-2008-3.jpg inflating: yjh/olympics-2008-5.jpg inflating: yjh/olympics-2008-4.jpg inflating: yjh/olympics-2008-1.jpg [root@localhost html]# ls ← 列出当前目录下的文件和文件夹 blog index.html phpinfo.php yjh yjh.zip ← 多出一个yjh文件目录,解压成功
tar压缩和解压缩
[root@localhost html]# rm -rf yjh.zip ← 列出当前目录下的文件和文件夹 [root@localhost html]# tar cvfz yjh.tar.gz ./yjh/ ← 把当前目录yjh压缩成yjh.tar.gz文件 ./yjh/ ./yjh/Thumbs.db ./yjh/olympics-2008-4.jpg ./yjh/20080506064.jpg ./yjh/20080506057.jpg ./yjh/20080506056.jpg ./yjh/20080506065.jpg ./yjh/olympics-2008-5.jpg ./yjh/20080506066.jpg ./yjh/20080506068.jpg ./yjh/olympics-2008-1.jpg ./yjh/olympics-2008-3.jpg ./yjh/20080506063.jpg ./yjh/olympics-2008-2.jpg ./yjh/20080506071.jpg [root@localhost html]# ls ← 列出当前目录下的文件和文件夹 blog index.html phpinfo.php yjh yjh.tar.gz ← 多了一个yjh.tar.gz压缩文件 [root@localhost html]# rm -rf yjh ← 删除yjh目录 [root@localhost html]# ls blog index.html phpinfo.php yjh.tar.gz [root@localhost html]# tar zxvf yjh.tar.gz ← 解压yjh.tar.gz文件 ./yjh/ ./yjh/Thumbs.db tar: ./yjh/Thumbs.db: time stamp 2008-05-06 11:35:56 is 63851 s in the future ./yjh/olympics-2008-4.jpg tar: ./yjh/olympics-2008-4.jpg: time stamp 2008-05-06 11:35:08 is 63802 s in the future ./yjh/20080506064.jpg tar: ./yjh/20080506064.jpg: time stamp 2008-05-06 03:13:52 is 33726 s in the future ./yjh/20080506057.jpg tar: ./yjh/20080506057.jpg: time stamp 2008-05-06 03:09:30 is 33464 s in the future ./yjh/20080506056.jpg tar: ./yjh/20080506056.jpg: time stamp 2008-05-06 03:09:18 is 33452 s in the future ./yjh/20080506065.jpg tar: ./yjh/20080506065.jpg: time stamp 2008-05-06 03:14:18 is 33752 s in the future ./yjh/olympics-2008-5.jpg tar: ./yjh/olympics-2008-5.jpg: time stamp 2008-05-06 11:34:30 is 63764 s in the future ./yjh/20080506066.jpg tar: ./yjh/20080506066.jpg: time stamp 2008-05-06 03:14:46 is 33780 s in the future ./yjh/20080506068.jpg tar: ./yjh/20080506068.jpg: time stamp 2008-05-06 03:22:06 is 34220 s in the future ./yjh/olympics-2008-1.jpg tar: ./yjh/olympics-2008-1.jpg: time stamp 2008-05-06 11:35:48 is 63842 s in the future ./yjh/olympics-2008-3.jpg tar: ./yjh/olympics-2008-3.jpg: time stamp 2008-05-06 11:33:14 is 63688 s in the future ./yjh/20080506063.jpg tar: ./yjh/20080506063.jpg: time stamp 2008-05-06 03:13:28 is 33702 s in the future ./yjh/olympics-2008-2.jpg tar: ./yjh/olympics-2008-2.jpg: time stamp 2008-05-06 11:32:36 is 63650 s in the future ./yjh/20080506071.jpg tar: ./yjh/20080506071.jpg: time stamp 2008-05-06 03:23:12 is 34286 s in the future tar: ./yjh: time stamp 2008-05-06 11:17:18 is 62732 s in the future [root@localhost html]# ls blog index.html phpinfo.php yjh yjh.tar.gz [root@localhost html]# cd yjh ← 进入解压后的yjh目录 [root@localhost yjh]# ls ← 列出当前目录下的文件和文件夹 20080506056.jpg 20080506065.jpg olympics-2008-1.jpg olympics-2008-5.jpg 20080506057.jpg 20080506066.jpg olympics-2008-2.jpg Thumbs.db 20080506063.jpg 20080506068.jpg olympics-2008-3.jpg 20080506064.jpg 20080506071.jpg olympics-2008-4.jpg [root@localhost yjh]#