by the following way we tar the folder presto-server-0.210 to file

tar -czvf presto-server-archive.tar.gz presto-server-0.210

so after we tar the folder , folder still exists

is it possible to use the tar or other approach and replace the folder to tar file , so folder will removed and instead of folder we create the tar file

  • 1
    if tar -czvf presto-server-archive.tar.gz presto-server-0.210; then rm -fr presto-server-0.210; fi? – DopeGhoti Apr 2 '19 at 21:03
  • I prefer not use rm -fr , is it possible ? – yael Apr 2 '19 at 21:06
  • @yael Any reason why you prefer not to use rm -r? – Kusalananda Apr 2 '19 at 21:15
  • the reason is because I need to use the script for all this tasks , and for safety I dont use rm -rf – yael Apr 2 '19 at 21:18
  • If you want to remove a directory and all of its contents, what alternative would you suggest exactly? – DopeGhoti Apr 2 '19 at 21:49

As noted in the comments, the proper way to do this is rm. For safety purposes, tar -jcvf folder.tar folder && rm -rf folder would only execute if the tar was successful - see "RETURN VALUE" section of the man page.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.