I'm trying to understand what's the proper way of using tar. I have a directory called main and in the sub directory it contains some files and directories I want to exclude. All others I want to remove. The command I use:
tar --remove-files --exclude main/sub/.runtime --exclude main/sub/.startTime --exclude main/sub/subsubdir -zcvf main.tar.gz main
But I get:
tar: main/sub: Cannot rmdir: Directory not empty
tar: Exiting with failure status due to previous errors
Now of course it the main/sub directory is not empty (because of the excluded files/directory). What's the proper way to resolve it without redirecting output to /dev/null or some other way? I want to still get errors but just not that one.