[BASH] How to create *.tgz file?
Hello!
Script to do: For every first-level, older than 3 months directories check if it has more than 1000 files in whole structure: * yes - for every second-level directory do *.tgz file, check if archive is buillt correctly and remove directories that are archived, * no - do nothing with it. Here is what I have so far. My main problems: 1. How to create archive for second-level directories? 2. How to fix problem with empty spaces in directory names? 3. How to correctly write part with checking *.tgz files and removing archived directories (now I'm getting errors: ls: you don't have permission to /root/dir/dir: There is no such file or directory)? Code:
for DIR in `find /root/* -maxdepth 1 -type d -mtime +90` ; do |
Unfortunately, because file names can have new line characters in them, find is highly limited command, which is hard to use right. To improve things over what you are doing now you cod do:
Code:
find /root/* -maxdepth 1 -type d -mtime +90 | while read DIR; do Second of all, always quote your variables. It's not always required, but if you are unsure, quote it. Furthermore, $(…) is preferred over backtics. And lastly, you should clean up .tgz file if tar command fails. Lastly, tar's return code can be used to determine whether you need to remove the directory. An as for counting number of files inside of a directory, find works better than ls -lR. Code:
if ! [ -f "$DIR.tgz" ] && blah.sh: Code:
find /root/* -maxdepth 1 -type d -mtime +90 -exec sh blah-helper.sh {} + Code:
for DIR; do |
I'm sorry for no response but I had problems with my health.
I did changes and code looks like this: Code:
find /root/ -maxdepth 1 -type d -mtime +90 | while read DIR ; do Folder 1 * Subfolder 1 * Subfolder 2 Folder 2 * Subfolder 1 * Subfolder 2 Script checks if there is 1000 files in Folder 1, Folder 2 and compress it. My question: can it do same thing but compress only Subfolder 1 and Subfolder 2 when there is 1000 files in whole Folder 1? I tried do to something but everything I do fails. |
All times are GMT -5. The time now is 11:28 AM. |