堆栈溢出。
我收集了一些工作笔记。 我把它们作为markdown文件保存,并且用日期和年份格式化它们 - 例如,今天的标题是06132017.md
我工作了一年,所以我有很多这样的文件。 我希望将命名约定从第一个月/第一年改为第一年,这样我就可以按字母顺序对它们进行排序,并轻松找到我需要的日期。
因此06132017.md将成为20170613.md - 这将使2016年和2017年不再按照aplha顺序混合。 是否有可以在文件夹上运行的命令来执行此操作?
StackOverflow.
I have a colleciton of notes from work. I keep them as markdown files, and had been formatting them with the date and year - for example, today's is titled 06132017.md
I am coming up on a year at work, so I have quite a few of these files. I wish to change the naming convention from month/day first to year first, so that I can sort them alphabetically and easily find dates I need.
So 06132017.md would become 20170613.md - this would keep 2016 and 2017 from mixing in aplha order. Is there a command I can run on a folder to do this?
最满意答案
如果您有Perl重命名实用程序,则执行起来相当简单:
$ prename 's/^(....)(....)(\.md)$/$2$1$3/' *.md 06132017.md renamed as 20170613.md点匹配任何字符,括号组,替换侧的$N插入组中捕获的字符。
或者只是在Bash:
$ for x in ????????.md ; do mv -v "$x" "${x:4:4}${x:0:4}.md" ; done '06132017.md' -> '20170613.md'${var:n:m}取一个长度为m的子字符串,从变量var位置n开始。
If you have the Perl rename utility, it's rather simple to do:
$ prename 's/^(....)(....)(\.md)$/$2$1$3/' *.md 06132017.md renamed as 20170613.mdThe dots match any character, the parenthesis group, and $N on the replacement side inserts the characters captured in the groups.
Or just in Bash:
$ for x in ????????.md ; do mv -v "$x" "${x:4:4}${x:0:4}.md" ; done '06132017.md' -> '20170613.md'${var:n:m} takes a substring of length m, starting at position n from variable var.
更多推荐
发布评论