Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

CP file same file name with few changes

Status
Not open for further replies.

longs

Programmer
Jul 27, 2007
31
US
HI all
I want to copy a file name. Please let me explain myself;

filename20070824

cp filename20070824 test_filename20070824

The problem I have is that I want to use * instead of the date. I want to cp it in such a way that it keeps the name of the file and just adds "test_" at the start of it.
there will be only one file, with the name starting with "filename*"

may be something like
cp filename* test_*

but this command creat a file with the name "test_*"
I want to have "test_filename20070824"

Thanks for your help
 
for fn in filename_*
do
[ -f $fn ] && cp $fn test_$fn
done

or some similar construction with more restrictive wildcards.



HTH,

p5wizard
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top