简体   繁体   English

使用'svn mv'将bash中目录中的每个文件大写

[英]Capitalize every file in a directory, in bash, using 'svn mv'

I need to change the capitalization of a set of files in a subversion working copy, like so: 我需要在subversion工作副本中更改一组文件的大小写,如下所示:

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. 标准的linux安装工具可用。

ls | ls | awk '{system("svn mv " $0 " " toupper(substr($0,1,1)) substr($0,2))}' 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. awk的优势在于它无处不在。

If you have a decent install you should have python, give this a try: 如果你有一个像样的安装你应该有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

I don't think theres an easy way to do it with bash/sed/tr/find. 我不认为用bash / sed / tr / find做一个简单的方法。

I'd make a Ruby/Perl script that does the renaming. 我会制作一个重命名的Ruby / Perl脚本。

 #!/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 {} + 

请注意,此更改会破坏Windows和Mac系统上现有的工作复印件,因为它们无法处理仅重命名的情况。

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. 我通常通过将'ls'输出重定向到文件来执行此操作,使用vim宏将每个文件名按到我想要的命令行,然后将该文件作为shell脚本执行。 It's crude but effective. 它粗糙但有效。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM