How would I be able to compress subdirectories into separate archives?
Example:
directory
subdir1
subdir2
Should create subdir1(.tar).gz and subdir2(.tar).gz
How would I be able to compress subdirectories into separate archives?
Example:
directory
subdir1
subdir2
Should create subdir1(.tar).gz and subdir2(.tar).gz
This small script seems to be your best option, given your requirements:
It properly handles directories with spaces in their names.
How about this:
find * -maxdepth 0 -type d -exec tar czvf {}.tar.gz {} \;
Explanation: You run a find on all items in the current directory. Maxdepth 0 makes it not recurse any lower than the arguments given. (In this case *, or all items in your current directory) The 'd' argument to "-type" only matches directories. Then exec runs tar on whatever matches. ({} is replaced by the matching file)
This will create a file called blah.tar.gz for each file in a directory called blah.
If you've got more than simply directories in directory (i.e. files as well, as ls will return everything in the directory), then use this:
The grep -v excludes the current directory which will show up in the
find
command by default.