Hey im stuck on a assignment and i dont know how to solve it really because iam quite new with working in linux. I have to place a directory in a tar-ball and zip it using gzip. At the moment this is my code but it wont work and i dont know what the problem is...
dir=$1
tar -cv/tmp/backupfile.tgz $dir
edit
link to add details or otherwise improve your question - reading the comment section is rather cumbersome, and comments are subject to removal by moderators without notice.man tar
. A key option is :-fFILE
or-f "FILE"
, which specify the file to be created (or read when extracting). CAREFUL: the filename is whatever is just after the "f", so "f" is usually the last option in a tar command :tar -cvzf /tmp/yourtarfile.tgz /path/to/dir_to_tar
. + (almost) always enclose variables in doublequotes to avoid many problems:dir="$1"
. ordir="${1:-arg1_not_specified}"
(so that tar will say an error about "arg1_not_specified", as it can't find a file with that name to tar). Homework: rewrite this portably, you can't use the z option (gnu only)