Sunday, May 28, 2023
51
rated 0 times [  51] [ 0]  / answers: 1 / hits: 69205  / 2 Years ago, thu, october 28, 2021, 12:13:16

For about 200 files in a directory I would like to add the String 1_ to the beginning of all filenames.



The filenames are, for example, DATASET_X_Y_Z and the result should be 1_DATASET_X_Y_Z.



I don't know a thing about Shell scripting, but maybe there is a one liner for the terminal.


More From » command-line

 Answers
5

  • rename 's/^/1_/' * for renaming all files in the current directory



or




  • rename 's/^/1_/' DATASET* for renaming all files in the current directory starting with DATASET in their name



Explanation: the expression s/^/1_/ says: "replace the beginning of the filename (that means this symbol -> ^)' with 1_".


[#44750] Saturday, October 30, 2021, 2 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
lassrake

Total Points: 400
Total Questions: 103
Total Answers: 98

Location: Netherlands
Member since Mon, Jun 22, 2020
3 Years ago
;