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...


tar -cv/tmp/backupfile.tgz $dir

  • Forgot to tell, but i get the error : refusing to write archive contents to terminal (missing -f option) Oct 29, 2021 at 13:58
  • Welcome to the site. You can always use the 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.
    – AdminBee
    Oct 29, 2021 at 14:07
  • and when the output says "missing -f option" what does that imply that you might have to do?
    – DopeGhoti
    Oct 29, 2021 at 14:07
  • 2
    see: 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" . or dir="${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) Oct 29, 2021 at 14:26
  • and you need to know if you need to create an archive file with the full /path/to/thatdirectory, or just as seen "from" within thatdirectory ... those are 2 very different archives (and that are extracted from different places) Oct 29, 2021 at 14:28


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.