Tar Commands

Here are two important tar commands on how to create and extract a tar.gz file.

Create a tar gzip file called “project.tar.gz” of a directory called “foo.”

tar -cvzf project.tar.gz foo

Untar the “project.tar.gz” file to a directory called bar.

tar -zxvf project.tar.gz bar

Get Directory Size

Here’s how to get the size of a directory.

du -sh /var/www

Output:

2.1GB    /var/www

Size of the directories and files one level down.

du -sh /var/www/*

Sort with biggest files from top to bottom.

du -sh /var/www/* | sort -rh

Top 5 biggest files from top to bottom.

du -sh /var/www/* | sort -rh | head -5