如何在 bash 中重命名列表中的文件?
我有一个包含如下文件名的文件:
my_cool_file.xxx
my_cool_file2.xxx
my_cool_file3.xxx
我有一个文件夹,其中包含:
some_file.xxx
some_file2.xxx
some_file3.xxx
我想要一个 bash 脚本从文件名文件中取出一行并重命名文件夹中的一个文件。
有办法做到这一点吗?
I have a file that contains filenames like this:
my_cool_file.xxx
my_cool_file2.xxx
my_cool_file3.xxx
I have a folder that has:
some_file.xxx
some_file2.xxx
some_file3.xxx
I would like to have a bash script to take one line from the filename file and rename one file in the folder.
Is there a way to do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
注意:这个答案一般来说不太好,但它解决了OP的问题。
所有文件都以_file.xxx或_fileN.xxx结尾吗?
基本上,您只想更改文件名的前缀吗?
假设我正确理解您的问题,并且没有数字的文件位于 file_list.txt 的最后,以下内容应该可以解决问题,
如果您想要,请在带有
mv
的行中注释实际行动发生。Note: This answer isn't that good generally, but it solved the OP's problem.
Do all files end with _file.xxx or _fileN.xxx?
Basically, is what you want to change just the prefix of the filenames?
Assuming I understand your problem correctly, and that the file without a number is last in file_list.txt the following should do the trick
Comment in the line with
mv
if you want the actual move to happen.或者,虽然不那么聪明,但仍然是另一种方法。
我的情况:
我的命令:
Or, less clever, but still another way to do it.
My case:
My commands: