View file using zcat in unix

zcat is a useful tool in unix that can allow one to view the contents of a zipped file, much like the cat command. This is very useful to see the contents of a large file without unzipping. This can potentially save a lot of time. An example of how to use zcat is as follows:

[root@computer files]# ls
file1.txt
[root@computer files]# cat file1.txt
this is file 1
[root@computer files]# gzip file1.txt
[root@computer files]# ls
file1.txt.gz
[root@computer files]# zcat file1.txt.gz
this is file 1
[root@computer files]# ls
file1.txt.gz

In the unix environment above there is a file called “file1.txt”. We view the contents of the file. Then gzip it. Notice in the next command we can still zcat the files to see the contents. Also notice after the zcat the file remains zipped. This is a useful way to not modify the file (such as unzipping) and still view the contents.

Be the first to comment

Leave a Reply