将 MKS 替换为 Powershell
有人可以将这两个脚本从 MKS 翻译成 Powershell 吗?我想从我们的 ETL 工具中删除 MKS 并使用 Powershell 来完成此操作,但没有能力
1) 文件大小=ls -l $1 | awk '{print $5}'
if [ $FileSize -ge 100000000 ];然后 分割-b 60000000 $1 $1 fi
2) 查找 $1 -type f -name *.txt -mtime +30 -exec rm {} \;
非常感谢 画了
can anybody please translate these two scripts from MKS into Powershell? i would like to remove MKS from our ETL tools and accomplish this with Powershell but do not have the chops
1)
FileSize=ls -l $1 | awk '{print $5}'
if [ $FileSize -ge 100000000 ]; then
split -b 60000000 $1 $1
fi
2)
find $1 -type f -name *.txt -mtime +30 -exec rm {} \;
thanks very much
drew
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
避免在这里使用标准别名(例如,可以使用
dir
或ls
而不是Get-ChildItem
):(无法回忆
split
的功能)(将
-whatif
添加到Remove-Item
以列出要删除的内容而不删除它们。)Avoiding using even standard aliases here (eg. can use
dir
orls
rather thanGet-ChildItem
):(can't recall function of
split
)(Add a
-whatif
to theRemove-Item
to list what would be deleted without deleting them.)1) 获取
$1
命名的文件的大小。如果大小超过 100 MB,split
将其分成每个 60 MB 的部分。MKS
PowerShell
注释:仅实现了问题所需的拆分功能,并仅在小文件大小上进行了测试。您可能需要查看
StreamReader
< /a> 和StreamWriter
执行更高效的缓冲 IO。2) 在
$1
命名的目录中,查找
所有具有.txt
扩展名且在三十多天前修改过的常规文件,并将其删除。MKS
PowerShell
注意:关闭
-WhatIf
开关以实际执行删除操作,而不是预览它。1) Get the size of the file named by
$1
. If the size is more than 100 megabytes,split
it into parts of 60 megabytes each.MKS
PowerShell
Notes: Only the split functionality needed by the question was implemented, and tested just on small file sizes. You may want to look into
StreamReader
andStreamWriter
to perform more efficient buffered IO.2) In the directory named by
$1
,find
all regular files with a.txt
extension that were modified over thirty days ago, and remove them.MKS
PowerShell
Notes: Take off the
-WhatIf
switch to actually perform the remove operation, rather than previewing it.