是否有选项可以阻止重命名命令在重命名后将文件从子目录移动到父目录?

是否有选项可以阻止重命名命令在重命名后将文件从子目录移动到父目录?

我在父目录中有以下子目录./

find . -type d|sort
.
./M1_DMSO_120h
./M1_DMSO_24h
./M1_GW4869_120h
./M1_GW4869_24h
./M2_DMSO_120h
./M2_DMSO_24h
./M2_GW4869_120h
./M2_GW4869_24h
./M3_DMSO_120h
./M3_DMSO_24h
./M3_GW4869_120h
./M3_GW4869_24h
find . -type f -maxdepth 2 |sort
./M1_DMSO_120h/GSM7073729_M1_DMSO_120h_barcodes.tsv.gz
./M1_DMSO_120h/GSM7073729_M1_DMSO_120h_features.tsv.gz
./M1_DMSO_120h/GSM7073729_M1_DMSO_120h_matrix.mtx.gz
./M1_DMSO_24h/GSM7073723_M1_DMSO_24h_barcodes.tsv.gz
./M1_DMSO_24h/GSM7073723_M1_DMSO_24h_features.tsv.gz
./M1_DMSO_24h/GSM7073723_M1_DMSO_24h_matrix.mtx.gz
./M1_GW4869_120h/GSM7073732_M1_GW4869_120h_barcodes.tsv.gz
./M1_GW4869_120h/GSM7073732_M1_GW4869_120h_features.tsv.gz
./M1_GW4869_120h/GSM7073732_M1_GW4869_120h_matrix.mtx.gz
./M1_GW4869_24h/GSM7073726_M1_GW4869_24h_barcodes.tsv.gz
./M1_GW4869_24h/GSM7073726_M1_GW4869_24h_features.tsv.gz
./M1_GW4869_24h/GSM7073726_M1_GW4869_24h_matrix.mtx.gz
./M2_DMSO_120h/GSM7073730_M2_DMSO_120h_barcodes.tsv.gz
./M2_DMSO_120h/GSM7073730_M2_DMSO_120h_features.tsv.gz
./M2_DMSO_120h/GSM7073730_M2_DMSO_120h_matrix.mtx.gz
./M2_DMSO_24h/GSM7073724_M2_DMSO_24h_barcodes.tsv.gz
./M2_DMSO_24h/GSM7073724_M2_DMSO_24h_features.tsv.gz
./M2_DMSO_24h/GSM7073724_M2_DMSO_24h_matrix.mtx.gz
./M2_GW4869_120h/GSM7073733_M2_GW4869_120h_barcodes.tsv.gz
./M2_GW4869_120h/GSM7073733_M2_GW4869_120h_features.tsv.gz
./M2_GW4869_120h/GSM7073733_M2_GW4869_120h_matrix.mtx.gz
./M2_GW4869_24h/GSM7073727_M2_GW4869_24h_barcodes.tsv.gz
./M2_GW4869_24h/GSM7073727_M2_GW4869_24h_features.tsv.gz
./M2_GW4869_24h/GSM7073727_M2_GW4869_24h_matrix.mtx.gz
./M3_DMSO_120h/GSM7073731_M3_DMSO_120h_barcodes.tsv.gz
./M3_DMSO_120h/GSM7073731_M3_DMSO_120h_features.tsv.gz
./M3_DMSO_120h/GSM7073731_M3_DMSO_120h_matrix.mtx.gz
./M3_DMSO_24h/GSM7073725_M3_DMSO_24h_barcodes.tsv.gz
./M3_DMSO_24h/GSM7073725_M3_DMSO_24h_features.tsv.gz
./M3_DMSO_24h/GSM7073725_M3_DMSO_24h_matrix.mtx.gz
./M3_GW4869_120h/GSM7073734_M3_GW4869_120h_barcodes.tsv.gz
./M3_GW4869_120h/GSM7073734_M3_GW4869_120h_features.tsv.gz
./M3_GW4869_120h/GSM7073734_M3_GW4869_120h_matrix.mtx.gz
./M3_GW4869_24h/GSM7073728_M3_GW4869_24h_barcodes.tsv.gz
./M3_GW4869_24h/GSM7073728_M3_GW4869_24h_features.tsv.gz
./M3_GW4869_24h/GSM7073728_M3_GW4869_24h_matrix.mtx.gz

现在,我想删除每个文件的标头,以便它们在每个子目录中看起来如下所示;

 barcodes.tsv.gz
 features.tsv.gz
 matrix.mtx.gz

我尝试使用rename 如下方法来执行此操作;

rename "s/M\d.+_//g"  M*/*

但重命名会将重命名的文件移动到父目录。

我的不太优雅的解决方案使用for loop and rename如下;

for i in $(cat dir.name) ; do cd $i ; rename  "s/GSM\d.+_//g"  *.gz ; cd .. ;done

我想知道是否有选项rename不使用for loop? 的情况下完成此任务

我的系统:

sw_vers
ProductName:        macOS
ProductVersion:     13.6
BuildVersion:       22G120

相关内容