小编And*_*yen的帖子

在Shell脚本中递归查找目录并重命名

我正在编写一个简单的 Shell 脚本,以便在 Linux 机器上运行,我将:

1) 在主目录中查找特定的子目录。这些子目录具有非常具体的命名约定(见下文),并且它们始终位于主目录下方最大深度 2 处。

2) 将这些子目录重命名为其原始名称的一部分。

例如,子目录命名为:

andrew-11111
andrew-11112
andrew-11113
andrew-11114
Run Code Online (Sandbox Code Playgroud)

到达这些子目录的路径如下所示:

myphotos/sailing/photos/andrew-1111
myphotos/sailing/photos/andrew-1112
myphotos/biking/photos/andrew-1113
myphotos/hiking/photos/andrew-1114
Run Code Online (Sandbox Code Playgroud)

我想从每个子目录中取出“andrew-”:

myphotos/sailing/photos/1111
myphotos/sailing/photos/1112
myphotos/biking/photos/1113
myphotos/hiking/photos/1114
Run Code Online (Sandbox Code Playgroud)

我已经“找到”了子目录并列出了它们。我还了解如何在命令行中复制和重命名。但以我的 shell 脚本知识水平将其组合起来花费的时间远远超出了我的承受能力。只是免责声明,我非常愿意学习,并且已经编写了一些 shell 脚本,但对此仍然陌生。非常感谢任何帮助或示例!

linux bash shell

2
推荐指数
1
解决办法
375
查看次数

标签 统计

bash ×1

linux ×1

shell ×1