Shell:按文件名获取最新文件的列表
我有类似的文件
update-1.0.1.patch
update-1.0.2.patch
update-1.0.3.patch
update-1.0.4.patch
update-1.0.5.patch
,并且我有一个包含最后应用的路径的变量(例如 update-1.0.3.patch)。所以,现在我必须获取要应用的文件列表(在示例中更新 1.0.4 和 1.0.5)。我怎样才能得到这样的列表?
为了澄清,我需要一种方法来获取给定文件按字母顺序排列在后面的文件列表,并且该文件列表也必须按字母顺序排列(显然并不总是可以应用补丁 1.0.0)。 1.0.4 之前的 5)。
I have files like
update-1.0.1.patch
update-1.0.2.patch
update-1.0.3.patch
update-1.0.4.patch
update-1.0.5.patch
And I have a variable that contains the last applied path (e.g. update-1.0.3.patch). So, now I have to get a list of files to apply (in the example updates 1.0.4 and 1.0.5). How can I get such list?
To clarify, I need a method to get a list of files that comes alphabetically later of given file and this list of files must be also in alphabetical order (obviously is not allways possible to apply the patch 1.0.5 before 1.0.4).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
sed
是打印行范围的首选工具。您给它一个开始/结束地址或模式以及在其之间执行的命令。这种排序可能不是必需的,因为
ls
可以按名称排序,但出于对维护者的礼貌,最好将其包含在内以表明必要性。 sed 的-n
意思是“不自动打印每一行”,-e
意思是“我在命令行上给你一个脚本”。我使用 " 将脚本括起来,$ENVVAR
将被评估。结束地址为空 (//
),p
意思是“打印该行”。哦,我刚刚注意到你只想要稍后的那些,可能有一种方法可以告诉 sed 在你的地址之后开始,但我会通过
tail -n 进行管道传输。 +2
从第二行开始。sed
is your go-to guy for printing ranges of lines. You give it a starting/ending address or pattern and command to do between.The sort probably isn't necessary because
ls
can sort by name, but it might be good to include as a courtesy to maintainers to show the necessity. The-n
to sed means "don't print every line automatically" and the-e
means "I'm giving you a script on the command line". I used " to enclose the script to that$ENVVAR
would be eval'd. The ending address is empty (//
) and thep
means "print the line".Oh, and I just noticed you only want the ones later. There's probably a way to tell sed to start on the line after your address, but instead I'd pipe it through
tail -n +2
to start on the second line.