使用 bash 将文件夹名重命名为文件名
Rename foldername to filename with bash
我想使用文件夹名称重命名文件。
这个:
├── foo01
│ └── bar.png
│ └── bar.txt
├── foo02
│ └── bar.png
│ └── bar.txt
└── foo03
└── bar.png
└── bar.txt
应该是这样的:
├── foo01
│ └── foo01.png
│ └── foo01.txt
├── foo02
│ └── foo02.png
│ └── foo02.txt
└── foo03
└── foo03.png
└── foo03.txt
我找不到执行此操作的方法。有人可以帮忙吗?
使用 Perl 的独立重命名命令:
rename -n 's|([^/]*)/[^/]*\.(.*)$|/.|' */*
输出:
foo01/bar.png renamed as foo01/foo01.png
foo01/bar.txt renamed as foo01/foo01.txt
foo02/bar.png renamed as foo02/foo02.png
foo02/bar.txt renamed as foo02/foo02.txt
foo03/bar.png renamed as foo03/foo03.png
foo03/bar.txt renamed as foo03/foo03.txt
如果一切正常,删除选项 -n
。
我想使用文件夹名称重命名文件。
这个:
├── foo01
│ └── bar.png
│ └── bar.txt
├── foo02
│ └── bar.png
│ └── bar.txt
└── foo03
└── bar.png
└── bar.txt
应该是这样的:
├── foo01
│ └── foo01.png
│ └── foo01.txt
├── foo02
│ └── foo02.png
│ └── foo02.txt
└── foo03
└── foo03.png
└── foo03.txt
我找不到执行此操作的方法。有人可以帮忙吗?
使用 Perl 的独立重命名命令:
rename -n 's|([^/]*)/[^/]*\.(.*)$|/.|' */*
输出:
foo01/bar.png renamed as foo01/foo01.png foo01/bar.txt renamed as foo01/foo01.txt foo02/bar.png renamed as foo02/foo02.png foo02/bar.txt renamed as foo02/foo02.txt foo03/bar.png renamed as foo03/foo03.png foo03/bar.txt renamed as foo03/foo03.txt
如果一切正常,删除选项 -n
。