Does tar have any option where, when creating an archive, if the target directory does not exist, it creates it on it's own?
So I got folders
/1/2 but I don't have folder
/1/2/3/. Is there any option I could use for tar to be able to make it?
I need it for a script, but if there is no option, would it just be better to do something like this?
mkdir /1/2/3/ &> /dev/null
If the folder isn't there, it's gonna get created, but if it already is there, I won't get an error massage because I shoved all of it into null.
Now with this method, is there ANYTHING that could go wrong?
Basically, I'm making a script that deletes users, but you can choose an option to archive their home directories before the script deletes the user. In order to make the script usable on other machines, I have to create a folder called
/archives, which may or may not exist on other machines.
Since tar apparently cannot recursively create whatever path you specify for the archive (for example it cannot create
/archives/users if you write
tar -czf /archives/users/user1.tgz /home/user1/ if
/archives does not exist.
Which lead me to my question about my solution: writing
mkdir -p /archives/users/ &> /dev/null. Would this mess up anything?
Keep in mind that this script can only be run with sudo, since it's a user deletion script.