bash 删除所有 ClearCase 视图私有文件的命令行
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/369697/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Command line to delete all ClearCase view-private files
提问by mbyrne215
I'm looking for a command line to remove all view-private files and directories from a ClearCase view on Windows. I have Cygwin available as well.
我正在寻找一个命令行来从 Windows 上的 ClearCase 视图中删除所有视图私有文件和目录。我也有 Cygwin 可用。
The script available at this articleis not quite what I want, since I'm working with a large number of files and want to delete them all without having to select each one.
本文中提供的脚本并不是我想要的,因为我正在处理大量文件并希望将它们全部删除而不必选择每个文件。
回答by VonC
A few remarks:
几点说明:
ct lsprivate
is great for dynamic views, not snapshot viewsct ls -rec -view_only
as well asct lsprivate
also list your checked-out files... I am not sure you want to delete those...
ct lsprivate
非常适合动态视图,而不是快照视图ct ls -rec -view_only
以及ct lsprivate
列出您签出的文件...我不确定您是否要删除这些...
For listing private files (only private ones, not hiHymaned ones you may want to keep), you need to have a command that:
要列出私人文件(仅私人文件,而不是您可能想要保留的被劫持的文件),您需要有一个命令:
- takes into account spaces in name
- does not list checkouts or hiHymaned or eclipsed files or symlinks
- works for both snapshot and dynamic views
(bonus) does not depend on external shell commands
for /F "usebackq delims=" %i in (`cleartool ls -r ^| find /V "Rule:" ^| find /V "hiHymaned" ^| find /V "eclipsed" ^| find /V "-->"`) do @echo "%i"
- 考虑名称中的空格
- 不列出结帐或劫持或黯然失色的文件或符号链接
- 适用于快照和动态视图
(奖励)不依赖于外部 shell 命令
for /F "usebackq delims=" %i in (`cleartool ls -r ^| find /V "Rule:" ^| find /V "hiHymaned" ^| find /V "eclipsed" ^| find /V "-->"`) do @echo "%i"
That lists all your private files (skipping the hiHymaned/eclipsed/checked-out or non-private ones as well as symlinks) in a pure Windows way (no external shell dependency needed).
Replace @echo "%i"
by del /F "%i"
and they are gone.
Note the double quotes around %i, in order to display/remove properly files with spaces in their name.
Also note the absence of the cleartool parameter -nxn, as symlinks would otherwise be indistinguishable and view-private files are not being decorated anyway.
它以纯 Windows 方式(不需要外部 shell 依赖项)列出了您的所有私有文件(跳过被劫持/蚀损/检出或非私有文件以及符号链接)。
替换@echo "%i"
为del /F "%i"
它们就消失了。
请注意 %i 周围的双引号,以便正确显示/删除名称中带有空格的文件。还要注意没有 cleartool 参数 -nxn,否则符号链接将无法区分,并且无论如何都不会修饰视图私有文件。
In order to also get rid of private directories, first run the command with rmdir /S /Q "%i"
and then with del /F "%i"
.
为了也摆脱私有目录,首先运行命令,rmdir /S /Q "%i"
然后运行del /F "%i"
。
回答by Rajinikanth
Under windows DOS prompt:
在 Windows DOS 提示符下:
for /f "delims=" %f in ('cleartool lspriv -s -do -oth ^| sort /r') do @del /f /q "%f"
回答by Mr. Muskrat
I know that there is probably a better way but I always seem to come back to this one:
我知道可能有更好的方法,但我似乎总是回到这个方法:
ct lspriv | grep -v checkedout | xargs rm -rf
回答by Paul Tomblin
I've always used:
我一直使用:
ct lsprivate | xargs rm
回答by Jonathan Leffler
On Unix (dynamic views), one very effective technique for removing view private files is to drop the view. Preserve the cspec first. Also make sure there are no checkouts in the view. Then remove it and recreate a new one (same name, same cspec, same storage, but no private files until you create them).
在 Unix(动态视图)上,删除视图私有文件的一种非常有效的技术是删除视图。首先保留 cspec。还要确保视图中没有结帐。然后删除它并重新创建一个新的(相同的名称、相同的 cspec、相同的存储,但在创建它们之前没有私有文件)。
# With the view to be cleaned as your current view...
ct pwv -s > /tmp/viewname
viewname=$(</tmp/viewname)
ct catcs > /tmp/$viewname.cs
ct lsview -cvi | awk '{print ;}' > /tmp/$viewname.vws
# The next line is the first dangerous line!
# It cancels all outstanding checkouts and removes the modified files
ct lsco -cvi -s -avo 2>/dev/null | xargs ct unco -rm # Or: xargs ct ci -nc
exit # Terminate the session in the view
viewname=$(</tmp/viewname)
rm /tmp/viewname
# The next line is the second dangerous line
ct rmview -tag $viewname
ct mkview -tag $viewname $(</tmp/$viewname.vws)
ct setcs -tag $viewname /tmp/$viewname.cs
rm /tmp/$viewname.cs
All view private files are gone - and you've minimized your disk usage.
所有视图私有文件都消失了 - 您已经最大限度地减少了磁盘使用量。
If you're lucky enough to only work with a single VOB, you can omit the '-avo
' (all VOBs) option. The '2>/dev/null
' redirection loses errors from inaccessible VOBs - I have more than 100 visible but inaccessible VOBs in my environment, apart from the dozen or so accessible ones that I really use.
如果您有幸只使用单个 VOB,则可以省略“ -avo
”(所有 VOB)选项。' 2>/dev/null
' 重定向丢失了无法访问的 VOB 的错误 - 除了我真正使用的十几个可访问的 VOB 之外,我的环境中有 100 多个可见但无法访问的 VOB。
Note that if you were packaging this as a 'rebuild.view
' script, you'd take the viewname as an argument (working from outside the view - it would not be the current view), and you could then do the cleanup inside the view, use a different 'lsview' option to get the details needed, and generally get away from the temporary storage in /tmp (though you'll need to cache the cspec somewhere).
请注意,如果您将其打包为“ rebuild.view
”脚本,则将视图名称作为参数(从视图外部工作 - 它不会是当前视图),然后您可以在视图内部进行清理,使用一个不同的“lsview”选项来获取所需的详细信息,并且通常会远离 /tmp 中的临时存储(尽管您需要将 cspec 缓存在某处)。
One other point to note - you would want to ensure that you've done a manual cleanup before letting the automatic loose. There should be no checkouts, for example. Alternatively, write the script to refuse to drop the view if there are any checkouts.
另一点需要注意 - 您需要确保在让自动松动之前已经完成了手动清理。例如,不应该有结帐。或者,编写脚本以在有任何结帐时拒绝删除视图。
回答by mbyrne215
I ended up using this command in Cygwin:
我最终在 Cygwin 中使用了这个命令:
cleartool ls -recurse -view_only | sed -e 's:\:/:g' | xargs rm -r
The sed is necessary to change the Windows-style paths output by cleartool into Unix-style paths. There's probably a more efficient command out there. This one throws a lot of errors, because it deletes the directory, and then any previously found view-private files underneath that directory will be not found by rm. But you get the right result in the end.
sed 是将 cleartool 输出的 Windows 样式路径更改为 Unix 样式路径所必需的。那里可能有一个更有效的命令。这个会抛出很多错误,因为它删除了目录,然后任何以前在该目录下找到的视图私有文件都不会被 rm 找到。但你最终会得到正确的结果。
EDIT: VonC points out that this only works with dynamic ClearCase views
编辑:VonC 指出这仅适用于动态 ClearCase 视图
回答by Vas
From the CLI To list the view private files executed the below command
for /F "usebackq delims=" %i in (`cleartool lspriv -s ^| find /V "Rule:" ^| find /V "hiHymaned" ^| find /V "eclipsed"`) do @echo "%i"
From the CLI executed below comand to delete the view private files
for /F "usebackq delims=" %i in (`cleartool lspriv -s ^| find /V "Rule:" ^| find /V "hiHymaned" ^| find /V "eclipsed"`) do del /F "%i"
Synchronizing the view with the project:
From the project explorer select the stream properties, go to the view tab, select the view properties then click the "synchronize with the project"
从 CLI 要列出执行以下命令的查看私有文件
for /F "usebackq delims=" %i in (`cleartool lspriv -s ^| find /V "Rule:" ^| find /V "hiHymaned" ^| find /V "eclipsed"`) do @echo "%i"
从下面执行的 CLI 命令删除查看私有文件
for /F "usebackq delims=" %i in (`cleartool lspriv -s ^| find /V "Rule:" ^| find /V "hiHymaned" ^| find /V "eclipsed"`) do del /F "%i"
将视图与项目同步:
从项目资源管理器中选择流属性,转到视图选项卡,选择视图属性,然后单击“与项目同步”
回答by Vas
what about use the of cygpath command instead of sed?
you can found more info about cygpath.exe here:
link text
使用 of cygpath 命令而不是 sed 怎么样?
您可以在此处找到有关 cygpath.exe 的更多信息:
链接文本
a way to link cygpath.exe with other programs is to use xargs.
example: processA | xargs cygpath -u > my-path-in-unix-format.txt
将 cygpath.exe 与其他程序链接的一种方法是使用 xargs。
示例:进程A | xargs cygpath -u > my-path-in-unix-format.txt
回答by Sam Mackrill
In pure windows you can do this:
在纯窗口中,您可以这样做:
for /F "delims=" %i IN ('ct lsprivate') DO rm -rf "%i"