Bulk file copy in unix with custom name

In Unix I have to copy bulk files from one folder to another they are in below form

FILE1_547804_550484_2013-12-19 21.15.32_913.pdf
FILE2_518868_616944_2014-01-03 21.10.49_718.pdf

but while copying to the destination want to remove time part and copy as below:

FILE1_547804_550484.pdf
FILE2_518868_616944.pdf

Here is the command that will help you, bolded part can be adjusted as per need:

ls -1|awk -F_ -v OFS=’_’ ‘{o=$0;gsub(/ /,”\\ “,o);NF-=2}$0=”cp “o ” “$0”.pdf”‘|sh

About nitingautam

I am Tech Lead (Java/J2EE/ExtJs) with a MNC located @ Gurgaon.
This entry was posted in unix and tagged , , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *