Zip command in centos

0
64

zip a single file with example

Lets create a new file, for immediate creation i am using output redirection, where output of command “ls -l” is redirecting to my filename “myFiles.txt”

root@mypc [~/test]# ls -l > myFiles.txt
Confirming file creation
root@mypc [~/test]# ls -lh
total 12K
drwxr-xr-x  2 root root 4.0K May 21 23:54 ./
dr-xr-x— 16 root root 4.0K May 21 23:53 ../
-rw-r–r–  1 root root  153 May 21 23:54 myFiles.txt

Now adding myFiles.txt into myFiles.zip

root@mypc [~/test]# zip myFiles.zip myFiles.txt
adding: myFiles.txt (deflated 39%)

Verifying zip creation

root@mypc [~/test]# ls -lh
total 16K
drwxr-xr-x  2 root root 4.0K May 21 23:54 ./
dr-xr-x— 16 root root 4.0K May 21 23:53 ../
-rw-r–r–  1 root root  153 May 21 23:54 myFiles.txt
-rw-r–r–  1 root root  265 May 21 23:54 myFiles.zip

Now create another file

root@mypc [~/test]# ls -ls > myFiles1.txt

Zip all two files together

root@mypc [~/test]# zip myFiles.zip myFiles.txt myFiles1.txt
updating: myFiles.txt (deflated 39%)
adding: myFiles1.txt (deflated 55%)
root@mypc [~/test]# ls -l
total 20
drwxr-xr-x  2 root root 4096 May 22 00:04 ./
dr-xr-x— 16 root root 4096 May 21 23:53 ../
-rw-r–r–  1 root root  273 May 22 00:03 myFiles1.txt
-rw-r–r–  1 root root  153 May 21 23:54 myFiles.txt
-rw-r–r–  1 root root  541 May 22 00:04 myFiles.zip

To read contents of zip file with out extracting

root@mypc [~/test]# unzip -l myFiles.zip
Archive:  myFiles.zip
Length      Date    Time    Name
———  ———- —–   —-
153  05-21-2015 23:54   myFiles.txt
273  05-22-2015 00:03   myFiles1.txt
———                     ——-
426                     2 files

To view content of a File inside the zip with out extracting full

root@mypc [~/test]# unzip -c myFiles.zip myFiles1.txt
Archive:  myFiles.zip
inflating: myFiles1.txt
total 16
4 drwxr-xr-x  2 root root 4096 May 22 00:03 ./
4 dr-xr-x— 16 root root 4096 May 21 23:53 ../
0 -rw-r–r–  1 root root    0 May 22 00:03 myFiles1.txt
4 -rw-r–r–  1 root root  153 May 21 23:54 myFiles.txt
4 -rw-r–r–  1 root root  265 May 21 23:54 myFiles.zip

LEAVE A REPLY

Please enter your comment!
Please enter your name here