but it's not working.
Hello all.
I'm running the following command to find files with a specific name and rename them, but the command prompt returns a short 10 seconds after executing and doesn't find or rename anything.
What am I doing wrong here?
find . -type f | for file in *_D.pdf; do new=`echo $file | cut -c-20`; mv $file $new.pdf; done
I should mention there are A LOT of files in the directories.
rdrtx1
March 24, 2016, 3:35pm
2
try something like:
find . -type f -name "*_D.pdf" | while read file ; do new=`echo $file | cut -c-20` ; mv "$file" "$new.pdf" ; done
RudiC
March 24, 2016, 3:52pm
3
Depending on the shell that you are running, this will speed up the processing of A LOT of files:
find . -type f -name "*_D.pdf" | while read file ; do mv "$file" "${file:0:20}.pdf" ; done
Are you sure that 20 chars will contain the relevant part of the files?
Tried that first but it gave the same error. So I removed the -name, thinking it would not look for the file twice.
---------- Post updated at 03:57 PM ---------- Previous update was at 03:54 PM ----------
rudic:
Depending on the shell that you are running, this will speed up the processing of A LOT of files:
find . -type f -name "*_D.pdf" | while read file ; do mv "$file" "${file:0:20}.pdf" ; done
Are you sure that 20 chars will contain the relevant part of the files?
This sure was faste, but it's not generating the correct new filename. I'm not familiar with ${file:0:20}. What does this do?
---------- Post updated at 03:59 PM ---------- Previous update was at 03:57 PM ----------
bbbngowc:
Tried that first but it gave the same error. So I removed the -name, thinking it would not look for the file twice.
---------- Post updated at 03:57 PM ---------- Previous update was at 03:54 PM ----------
This sure was faste, but it's not generating the correct new filename. I'm not familiar with ${file:0:20}. What does this do?
Oh I see what it does. I just need to modify it to 26 and it works.
Many thanks.