I'm looking for a single line command or a script that archives 5 folders into .tar files (no gzip/bzip needed) in a certain directory and deletes the folders after a successful compression. It has to use the original folder name as file name for the archive too.
So far I've used the current command, which only does one directory per time:
tar -c directory > directory.tar && rm -rf directory
Thanks in advance.
it's a bit lengthy but:
edit;
tar -cf dir.tar dir
is a little more concise thantar -c dir > dir.tar
example script:
you can plop that into
script.sh
,chmod 755 script.sh
and then run it likescript.sh directory
however, you could add a lot more to it, to get a list of directories from your main directory, and even use a file to keep track of the last time
directory
was archived, so you can set your maximum, etc.This will process the first five directories under the directory passed as an argument to the script.
I'm curious about the reason for the limit.