简体   繁体   中英

bash script copy multiple folders and files logic

Bash Script: Each file inside table directories will need be renamed from keyspace to newkyespace_456 when it is copied to destination.

└── Main_folder
    ├── keyspace
    │   ├── tableA-12323/keyspace-tableA-12323-ka-1-Data.db
    │   ├── tableB-123425/keyspace-tableA-123425-ka-1-Data.db
    │   └── tableC-12342/keyspace-tableA-12342-ka-1-Data.db
    └── newkeyspace_456 ( given folder) and sub folders
        ├── tableA-12523 
        ├── tableB-173425
        └── tableC-1242

Example is keyspace/tableA-12323/keyspace-tableA-12323-ka-1-Data.db to newkeyspace_456/tableA-12523/newkeyspace_456-tableA-12523-ka-1-Data.db

Note that same table (Type A , B , C) type can be copied to same table type in other keyspaces (Type A , B , C) . The table name also need changes in file name , please note in example 12323 has been renamed to 12523 when copied to diretory newkeyspace_456/tableA-12523.

Type A table files can be copied from keyspace/tableA-12323 to Type A table files in newkeyspace_456/tableA-12523.

How do I approach this problem?

Thanks tom

使用参数扩展和字符串替换来更改文件名,如下所示:

for fn in $(find ./keyspace -path '*.db') ; do cp "$fn" "${fn//keyspace/newkeyspace_456}" ; done ;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM