Ok, sometimes you just need to save some space and you don't want to create an archive.
Or perhaps you have some kind of backup utility that for some reason doesn't do what you asked for and you need to unzip EVERY file it created in a n-level directory tree.
What to do now? Manually zip/unzip every single file? Take your last remaining hair off?
No, you use the shell find command. Period.
How? Simple. To compact every single file:
[me@mybox]$ find . -type f -print0 | xargs -0 /bin/gzip
To unpack all those files:
[me@mybox]$ find . -name "*.gz" -print0 | xargs -0 /bin/gunzip
Nice right?
Ok some explanations:
1) For both cases we use the find command (yeah) to... find and we pipe the results for xargs (ok, I won't explain what xargs does, so please: man xargs... come on I already helped you a lot here);
2) We use the option -print0 so it can understand we might have names with spaces or whatever other weird character in the file name, so it will quote the filename; and
3) On the first case (to compress) we only specify we want to compact all files of type "f" - file - so we exclude directories, symlinks and dwarfs;
That's it.
Nenhum comentário:
Postar um comentário