名前を変更した後、[名前の変更]コマンドがファイルをサブディレクトリから親ディレクトリに移動しないようにするオプションはありますか?

名前を変更した後、[名前の変更]コマンドがファイルをサブディレクトリから親ディレクトリに移動しないようにするオプションはありますか?

親ディレクトリ内に次の子ディレクトリがあります。/

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

ベストアンサー1

おすすめ記事