簡體   English   中英

使用'svn mv'將bash中目錄中的每個文件大寫

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

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

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

如何自動完成此過程? 標准的linux安裝工具可用。

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

顯然,其他腳本語言也可以正常工作。 awk的優勢在於它無處不在。

如果你有一個像樣的安裝你應該有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

我不認為用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 {} + 

請注意,此更改會破壞Windows和Mac系統上現有的工作復印件,因為它們無法處理僅重命名的情況。

我通常通過將'ls'輸出重定向到文件來執行此操作,使用vim宏將每個文件名按到我想要的命令行,然后將該文件作為shell腳本執行。 它粗糙但有效。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM