I have few files in the following directory: /var/lib/jenkins/bin/
-rwxr-xr-x. 1 root root 4430846 Apr 27 09:45 01-DSP-04.12_03_crc.bin
-rwxr-xr-x. 1 root root 1659036 Apr 27 09:45 01-FL4-04.12_02-crc.bin
-rwxr-xr-x. 1 root root 1659036 Apr 27 09:45 01-FL8-04.12_02-crc.bin
-rwxr-xr-x. 1 root root 1659036 Apr 27 09:46 01-FPGA-04.12_02-crc.bin
-rwxr-xr-x. 1 root root 524328 Apr 27 09:46 01-MMI-04.11_05-crc.bin
-rwxr-xr-x. 1 root root 27692 Apr 27 09:46 01-PIC-04.11_06-crc.bin
Also, I have a script that does some work at /var/lib/jenkins/scripts/my_script.sh
.
I want to remove the leading "01-" from the file names from this script. Is there any good way of doing this?
I tried the solution from https://stackoverflow.com/questions/28305134/remove-first-n-character-from-bunch-of-file-names-with-cut but do not work for me.
I get output like this:
Command
$ for file in /var/lib/jenkins/bin/*; do echo mv $file `echo $file | cut -c4-`; done
Output
mv /var/lib/jenkins/bin/01-DSP-04.12_03_crc.bin r/lib/jenkins/bin/01-DSP-04.12_03_crc.bin
mv /var/lib/jenkins/bin/test.sh r/lib/jenkins/bin/test.sh
As you can see it removes first 3 character which is directory name, not file name. I want to remove 3 character after 21 character from file name.
Any better way to do this?
for i in 01-?*; do mv -v "$i" "${i:3}"; done
– Apr 27 '17 at 15:10