create tar with multiple directories and file locations

You can just use

tar -cf myfile.tar /etc/dir1 /var/www/html /home/somedir

also, you could use

tar -czf myfile.tar.gz /etc/dir1 /var/www/html /home/somedir

This second example (note the z in the -czf parameter) will compress the tar file using g(z)ip.


This works for me small change by adding "change to directory DIR (C)" argument

tar -zcvf myfile.tar -C /etc/dir1 /var/www/html /home/somedir