You might need to zip a number of files, folders and sub folders to keep as a backup .
To zip the folders and subfolders:
tar -cvzf mytarfile.tar.gz mydir/
This will create a new gzip file of your entire folder mydir/ no matter how many files or sub folders in that
To untar a gzip file :
tar -xf mytarfile.tar.gz
So you might get an error if you give the full path for the files/folders with tar. This actually a feature, not a problem. But this might cause problems when running tar from a script .
tar: Removing leading `/' from member names
You can use the –absolute-names or -P with your tar
tar -cvzf bkup.tar.gz --absolute-names /home/ubuntu/
tar -cvzfp bkup.tar.gz /home/ubuntu/
But this results in an archive that extracts in complete paths . So if you don’t need leading slashes in a tar archive , you can also use -C / option :
tar -cvzf bkup.tar.gz -C / /home/ubuntu/