LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   How to copy in rename/ren tool's control ability (https://www.linuxquestions.org/questions/programming-9/how-to-copy-in-rename-ren-tools-control-ability-4175717899/)

BudiKusasi 10-18-2022 08:29 PM

How to copy in rename/ren tool's control ability
 
How do we or what tool to copy just in rename or ren utility control ability, simply do such but the source keep untouched ?

dugan 10-18-2022 10:29 PM

Your English is terrible, but if you're asking what I think you're asking, then use "mv". If you're not using it across filesystems, then it only changes the directory entry. The file's disk blocks are untouched.

Turbocapitalist 10-18-2022 11:20 PM

I can't think of a way to copy and rename in one step. Perhaps others can.

If you don't have any commas in the file names, you could try parsing the output of rename into a file and then running that file as a script. The rename utility can use multile Perl expressions, so here are two. One is to do the renaming of the file, the other is to modify the directory. Adjust as needed. Perl is used to modify the output instead of sed because there is no equivalent to non-greedy matching in sed:

Code:

rename -n -v 's/old/new/; s|^|/path/to/destination/|;' * \
    | perl -p -e 's/^.*?\(/cp -p /; s/, / /; s/\)$//;' \
    > ren

nano ren

. ren

Otherwise, you'll probably have to just manually enumerate the files into a script and then edit that script by hand to do what you want.

astrogeek 10-18-2022 11:37 PM

Quote:

Originally Posted by Turbocapitalist (Post 6387082)
Otherwise, you'll probably have to just manually enumerate the files into a script and then edit that script by hand to do what you want.

I agree with this! I have wasted more time trying to figure out how to copy/move and rename groups of files with a single command than it usually takes to list them into a file, use a few (safe) regular expressions or manual edits to translate those into commands then execute the file, possibly after testing an example manually.


All times are GMT -5. The time now is 08:12 AM.