Unix脚本查找目录中的所有文件夹,然后使用tar并将其移动 [英] Unix script to find all folders in the directory, then tar and move them
问题描述
基本上,我需要运行Unix脚本来查找目录/fss/fin中的所有文件夹(如果存在);然后我把它焦油了,然后移到另一个目录/fs/fi.
Basically I need to run a Unix script to find all folders in the directory /fss/fin, if it exists; then I have tar it and move to another directory /fs/fi.
到目前为止,这是我的命令:
This is my command so far:
find /fss/fin -type d -name "essbase" -print
在这里,我直接提到了文件夹名称 essbase
.但是,相反,我想在/fss/fin
中找到所有文件夹,并全部使用它们.
Here I have directly mentioned the folder name essbase
. But instead, I would like to find all the folders in the /fss/fin
and use them all.
如何在/fss/fin
目录&中找到所有文件夹tar将其移动到/fs/fi
?
How do I find all folders in the /fss/fin
directory & tar them to move them to /fs/fi
?
说明1:
是的,我只需要使用Unix Shell脚本在目录
/fss/fin
中找到所有文件夹,然后将它们压缩到另一个目录/fs/fi
中./p>
Yes I need to find only all folders in the directory
/fss/fin
directory using a Unix shell script and tar them to another directory/fs/fi
.
说明2:
我想明确要求.Shell脚本应包含:
I want to make it clear with the requirement. The Shell Script should contain:
- 找到目录
/fss/fin
中的所有文件夹 - 存放文件夹
- 将文件夹移动到服务器
s11003232sz.net
上的另一个目录 - 应用户要求,应将文件夹解压缩并将其移回原始目录
/fss/fin
/fs/fi
中推荐答案
这是我正在使用的示例,可能会引导您朝正确的方向
here is an example I am working with that may lead you in the correct direction
BackUpDIR="/srv/backup/"
SrvDir="/srv/www/"
DateStamp=$(date +"%Y%m%d");
for Dir in $(find $SrvDir* -maxdepth 0 -type d );
do
FolderName=$(basename $Dir);
tar zcf "$BackUpDIR$DateStamp.$FolderName.tar.gz" -P $Dir
done
这篇关于Unix脚本查找目录中的所有文件夹,然后使用tar并将其移动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!