Different count for compressed file listing vs directory listing

compressionlstar

I was taking a backup of a folder, where I used the following command :

sudo tar -zcvf www.tar.gz /var/www/

It successfully compressed, just for verifying the number of files in the compressed archive, and the directory I ran the following commands :

sudo tar -ztvf www.tar.gz | wc -l -> 186364

ls -R /var/www | wc -l -> 196440

How come the count is different, what am I missing ?

Best Answer

Look at the output without piping to wc to see the difference

$ ls -R www | cat
www:
dir1
dir2
file1

www/dir1:
file1

www/dir2:
file1
file2
$ ls -R www | wc -l
11

And

$ tar xvfz www.tar.gz
www/
www/dir1/
www/dir1/file1
www/dir2/
www/dir2/file1
www/dir2/file2
www/file1
$ tar xvfz www.tar.gz |wc -l
7

ls -R just produces some more output.