linux - 无法重命名...没有这样的文件或目录

标签 linux find rename

我有一些文件需要递归重命名。所以我执行命令 find shop-bill -depth -type f -exec rename -v "s/shop/shop-bill/"{} + ,但它给了我以下错误。我对没有这样的文件或目录错误感到困惑,但我可以确认这些文件确实存在。

liudonghua@desktop-ldh:/mnt/d/code/node/nestjs-sequelize-typescript/src$ find shop-bill -depth -type f -exec rename -v "s/shop/shop-bill/" {} +
Can't rename shop-bill/dto/shop.dto.ts shop-bill-bill/dto/shop.dto.ts: No such file or directory
Can't rename shop-bill/shop.controller.ts shop-bill-bill/shop.controller.ts: No such file or directory
Can't rename shop-bill/shop.entity.ts shop-bill-bill/shop.entity.ts: No such file or directory
Can't rename shop-bill/shop.module.ts shop-bill-bill/shop.module.ts: No such file or directory
Can't rename shop-bill/shop.providers.ts shop-bill-bill/shop.providers.ts: No such file or directory
Can't rename shop-bill/shop.service.ts shop-bill-bill/shop.service.ts: No such file or directory
liudonghua@desktop-ldh:/mnt/d/code/node/nestjs-sequelize-typescript/src$
liudonghua@desktop-ldh:/mnt/d/code/node/nestjs-sequelize-typescript/src$ ll shop-bill/dto/shop.dto.ts
-rwxrwxrwx 1 liudonghua liudonghua 879 May 29 17:17 shop-bill/dto/shop.dto.ts*
liudonghua@desktop-ldh:/mnt/d/code/node/nestjs-sequelize-typescript/src$ tree shop-bill
shop-bill
├── dto
│   └── shop.dto.ts
├── shop.controller.ts
├── shop.entity.ts
├── shop.module.ts
├── shop.providers.ts
└── shop.service.ts

1 directory, 6 files
liudonghua@desktop-ldh:/mnt/d/code/node/nestjs-sequelize-typescript/src$

奇怪的是我可以像这样成功执行类似的命令。

liudonghua@desktop-ldh:/mnt/d/code/node/nestjs-sequelize-typescript/src$
liudonghua@desktop-ldh:/mnt/d/code/node/nestjs-sequelize-typescript/src$ tree operator-bill
operator-bill
├── dto
│   └── shop.dto.ts
├── shop.controller.ts
├── shop.entity.ts
├── shop.module.ts
├── shop.providers.ts
└── shop.service.ts

1 directory, 6 files
liudonghua@desktop-ldh:/mnt/d/code/node/nestjs-sequelize-typescript/src$ find operator-bill -depth -type f -exec rename -v "s/shop/operator-bill/" {} +
operator-bill/dto/shop.dto.ts renamed as operator-bill/dto/operator-bill.dto.ts
operator-bill/shop.controller.ts renamed as operator-bill/operator-bill.controller.ts
operator-bill/shop.entity.ts renamed as operator-bill/operator-bill.entity.ts
operator-bill/shop.module.ts renamed as operator-bill/operator-bill.module.ts
operator-bill/shop.providers.ts renamed as operator-bill/operator-bill.providers.ts
operator-bill/shop.service.ts renamed as operator-bill/operator-bill.service.ts
liudonghua@desktop-ldh:/mnt/d/code/node/nestjs-sequelize-typescript/src$
liudonghua@desktop-ldh:/mnt/d/code/node/nestjs-sequelize-typescript/src$ rename -v
Usage:
    rename [ -h|-m|-V ] [ -v ] [ -n ] [ -f ] [ -e|-E perlexpr]*|perlexpr
    [ files ]

liudonghua@desktop-ldh:/mnt/d/code/node/nestjs-sequelize-typescript/src$ rename -V
/usr/bin/rename using File::Rename version 0.20

liudonghua@desktop-ldh:/mnt/d/code/node/nestjs-sequelize-typescript/src$

最佳答案

最后我发现了问题,原来是父目录也改名了。

liudonghua@desktop-ldh:/mnt/d/code/node/nestjs-sequelize-typescript/src$ find shop-bill -depth -type f -exec rename -n "s/shop/shop-bill/" {} +
rename(shop-bill/dto/shop.dto.ts, shop-bill-bill/dto/shop.dto.ts)
rename(shop-bill/shop.controller.ts, shop-bill-bill/shop.controller.ts)
rename(shop-bill/shop.entity.ts, shop-bill-bill/shop.entity.ts)
rename(shop-bill/shop.module.ts, shop-bill-bill/shop.module.ts)
rename(shop-bill/shop.providers.ts, shop-bill-bill/shop.providers.ts)
rename(shop-bill/shop.service.ts, shop-bill-bill/shop.service.ts)
liudonghua@desktop-ldh:/mnt/d/code/node/nestjs-sequelize-typescript/src$ ll shop-bill-bill/dto/shop.dto.ts
ls: cannot access 'shop-bill-bill/dto/shop.dto.ts': No such file or directory
liudonghua@desktop-ldh:/mnt/d/code/node/nestjs-sequelize-typescript/src$
liudonghua@desktop-ldh:/mnt/d/code/node/nestjs-sequelize-typescript/src$ cd shop-bill
liudonghua@desktop-ldh:/mnt/d/code/node/nestjs-sequelize-typescript/src/shop-bill$
liudonghua@desktop-ldh:/mnt/d/code/node/nestjs-sequelize-typescript/src/shop-bill$ find . -depth -type f -exec rename -n "s/shop/shop-bill/" {} +
rename(./dto/shop.dto.ts, ./dto/shop-bill.dto.ts)
rename(./shop.controller.ts, ./shop-bill.controller.ts)
rename(./shop.entity.ts, ./shop-bill.entity.ts)
rename(./shop.module.ts, ./shop-bill.module.ts)
rename(./shop.providers.ts, ./shop-bill.providers.ts)
rename(./shop.service.ts, ./shop-bill.service.ts)
liudonghua@desktop-ldh:/mnt/d/code/node/nestjs-sequelize-typescript/src/shop-bill$ find . -depth -type f -exec rename -v "s/shop/shop-bill/" {} +
./dto/shop.dto.ts renamed as ./dto/shop-bill.dto.ts
./shop.controller.ts renamed as ./shop-bill.controller.ts
./shop.entity.ts renamed as ./shop-bill.entity.ts
./shop.module.ts renamed as ./shop-bill.module.ts
./shop.providers.ts renamed as ./shop-bill.providers.ts
./shop.service.ts renamed as ./shop-bill.service.ts
liudonghua@desktop-ldh:/mnt/d/code/node/nestjs-sequelize-typescript/src/shop-bill$

关于linux - 无法重命名...没有这样的文件或目录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56370493/

相关文章:

regex - Bash 脚本 sed -e

c - 内核3.3.8中process_backlog和softnet_data字段的理解

regex - 如何在linux中使用find指定删除名为 "abc"或 "def"的子目录

linux - 查找并替换树中的字符串。递归

c - socketpair() 以只读方式打开套接字端?

eclipse-plugin - 用于在 Eclipse 工作区树中查找资源的 API

mysql - 使用 if 条件进行 FIND 和 REPLACE 的 SQL 查询

PHP 重命名() file_exists()

java - 使用java重命名文件夹中的所有文件

在 Windows 和 Linux 上使用 Apache 的 PHP MSSQL