3

I have a parent directory composed of a set of sub-directories. Each sub-directory is composed of a list of files.

Here is the scenario:

v_1:
filenames.txt

v_2:
labels.txt

v_3:
coding.txt

What is my expected output?

v_1:
v_1_filenames.txt

v_2:
v_2_labels.txt

v_3:
v_3_coding.txt

What l have tried to solve that?

rename -n 's/(.*)\//$1\/$1_/' */*

which prints

rename(v_1/filenames.txt, v_1/v_1_filenames.txt)
rename(v_2/labels.txt, v_2/v_2_labels.txt)
rename(v_3/coding.txt, v_3/v_3_coding.txt)

However it doesn't work. To confirm that I did:

ls *

and I get:

v_1:
filenames.txt

v_2:
labels.txt

v_3:
coding.txt

Any cue? Thank you

wjandrea
  • 14,236
  • 4
  • 48
  • 98
Josselin
  • 193

1 Answers1

3

Simply remove the option -n. From man prename*:

-n, --no-act
        No Action: show what files would have been renamed.

* There are multiple commands called rename; I assume you're using prename on Ubuntu 16.04 or earlier, though option -n does the same thing for most other versions. For details see What's the difference between the different "rename" commands?

wjandrea
  • 14,236
  • 4
  • 48
  • 98
  • Thank you for your answer @wjandrea. I tested it but it doesn't work for large directories. I have 13,000 sub-directories each contain about 300 files. So l tried ls | xargs rename 's/(.)//$1/$1_/' /* and l still get -bash: /usr/bin/xargs: Argument list too long – Josselin Oct 08 '18 at 07:35
  • https://askubuntu.com/questions/1081884/bash-usr-bin-rename-argument-list-too-long – Josselin Oct 08 '18 at 07:46