LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   need help in cp command (https://www.linuxquestions.org/questions/linux-newbie-8/need-help-in-cp-command-590906/)

deeptinegi 10-10-2007 06:04 PM

need help in cp command
 
i was changing one dos command to linux command, its like:

copy c:\file.mdl c:\data\file_dd.m*

That is the file extension should be the same as the source file(we can have file.mdl, file.mdo..).In linux i did this

cp /folder1/file.mdl /folder/folder1/file_dd.md*
i am getting md* instead of the correct file extension.

Can anybody help me :( :( i am just a beginer

The_JinJ 10-10-2007 06:31 PM

This will work
cp /folder1/file.md? /folder/folder1/

or for anything with .md* extension even more than 3 chars

cp /folder1/file.md* /folder/folder1/

AceofSpades19 10-10-2007 06:35 PM

its because that copies file.mdl to /folderfolder/file_dd.md, I think you want cp /folder/file.md* /folder/folder1/ which copies any files in /folder with any extension beginning with md to /folder/folder1

rsashok 10-10-2007 06:49 PM

Try this bash script, lets call it 'kacp' (kick ass copy):

Code:

#!/bin/bash

if [ $# -eq 0 ]; then
  echo "Usage: `basename $0` file.name"
  exit 0
fi

filename=$1
ext=${filename##*.}
base=${filename%%.*}

echo
echo Copying file: /folder1/$1  to /folder1/"$base"_dd."$ext"

cp /folder1/$1 /folder1/"$base"_dd."$ext"

Then you should execute it as:

Code:

kacp file.mdl
You need to change source and destination paths in the script from 'folder1' to a real name. But you got the idea....


All times are GMT -5. The time now is 01:38 AM.