1

I have a main directory bp and it has many sub-directories bp01, bp02, bp04. In each directory it has a file and the name of each file is randomly but start with co. I want to change each file name the same as its parent directory.

The following is the structure of my folder:

enter image description here

I want it look like this:

enter image description here

I am green hand in Linux,hope some one can help me. Thank you:)

2
  • For future please don't post images of text. Output of GUI terminal can easily be copied via Ctr + Shift + C in most modern terminals – Sergiy Kolodyazhnyy Nov 8 '18 at 6:18
  • 1
    Thank you for the kind suggestion and explanation Sergiy:))) – latenigyh Nov 10 '18 at 8:54
1

maybe this can help you:

cd bp
for subdir in ./*; do mv -v ./"$subdir"/*.nii ./"$subdir"/"$subdir".nii; done;
3
  • 1
    I got the same problem once, and thanks to quick search on google I found this tip on link – abaddon s Nov 8 '18 at 5:19
  • Hi :) Welcome to AskUbuntu. You can edit your question to include additional details such as those in your comment. I'll process this editr for you this time as an example. Also, well done on the formatting! – Wilhelm Erasmus Nov 8 '18 at 6:12
  • Thank you for your kind help:))) I will study further. – latenigyh Nov 10 '18 at 9:08

Not the answer you're looking for? Browse other questions tagged or ask your own question.