在 bash 中,使用“svn mv”将目录中的每个文件大写;

发布于 2024-07-07 08:54:23 字数 197 浏览 4 评论 0原文

我需要更改 subversion 工作副本中一组文件的大小写,如下所示:

svn mv test.txt Test.txt
svn mv test2.txt Test2.txt
svn mv testn.txt Testn.txt
...
svn commit -m "caps"

如何自动化此过程? 提供标准 Linux 安装工具。

I need to change the capitalization of a set of files in a subversion working copy, like so:

svn mv test.txt Test.txt
svn mv test2.txt Test2.txt
svn mv testn.txt Testn.txt
...
svn commit -m "caps"

How can I automate this process? Standard linux install tools available.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

愛上了 2024-07-14 08:54:24

如果你安装得当,你应该有 python,试试这个:

#!/usr/bin/python
from os import rename, listdir
path = "/path/to/folder"
try:
    dirList = listdir(path)
except:
    print 'There was an error while trying to access the directory: '+path
for name in dirList:
    try:
        rename(path+'\\'+name, path+'\\'+name.upper())
    except:
        print 'Process failed for file: '+name

If you have a decent install you should have python, give this a try:

#!/usr/bin/python
from os import rename, listdir
path = "/path/to/folder"
try:
    dirList = listdir(path)
except:
    print 'There was an error while trying to access the directory: '+path
for name in dirList:
    try:
        rename(path+'\\'+name, path+'\\'+name.upper())
    except:
        print 'Process failed for file: '+name
谢绝鈎搭 2024-07-14 08:54:24

我认为没有一种简单的方法可以使用 bash/sed/tr/find 来做到这一点。

我会制作一个 Ruby/Perl 脚本来进行重命名。

 #!/usr/bin/ruby 
 #  Upcase.rb 
 ARGV.each{ |i|
  newname = i.gsub(/(^.|\s.)/{ |x| x.upcase }
  `svn mv "#{i}" "#{newname}" `
 }

然后就做

 ./Upcase.rb foo.txt test.txt test2.txt foo/bar/test.txt 

或者如果你想做整个目录

 find ./ -exec ./Upcase.rb {} + 

I don't think theres an easy way to do it with bash/sed/tr/find.

I'd make a Ruby/Perl script that does the renaming.

 #!/usr/bin/ruby 
 #  Upcase.rb 
 ARGV.each{ |i|
  newname = i.gsub(/(^.|\s.)/{ |x| x.upcase }
  `svn mv "#{i}" "#{newname}" `
 }

Then just do

 ./Upcase.rb foo.txt test.txt test2.txt foo/bar/test.txt 

or if you want to do a whole dir

 find ./ -exec ./Upcase.rb {} + 
飘然心甜 2024-07-14 08:54:24

请注意,此更改会破坏 Windows 和 Mac 系统上的现有工作副本,因为它们无法处理仅大小写重命名。

Please note that this change breaks existing workingcopies on Windows and Mac systems, as they can't handle case only renames.

古镇旧梦 2024-07-14 08:54:24

我通常通过将 'ls' 输出重定向到文件,使用 vim 宏将每个文件名调整到我想要的命令行中,然后将文件作为 shell 脚本执行。 这很粗糙但很有效。

I typically do this by redirecting the 'ls' output to a file, using vim macros to massage each filename into the command line I want, then execute the file as a shell script. It's crude but effective.

你与清晨阳光 2024-07-14 08:54:23

LS | awk '{system("svn mv " $0 " " toupper(substr($0,1,1)) substr($0,2))}'

显然,其他脚本语言也可以工作。 awk 的优点是它无处不在。

ls | awk '{system("svn mv " $0 " " toupper(substr($0,1,1)) substr($0,2))}'

obviously, other scripting languages will work just as well. awk has the advantage that it it ubiquitous.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文