![]() |
cp command omitting directories
Hi
I'm using the follwoing command to copy some files from one folder to another, while doing this, i'm getting the following error: Code:
But the same thing when i'm trying without using wild character its working. Code:
>find /home/susee/data/A/1/C/ -type f -name "*.254" | xargs -i cp "{}" /home/susee/databkp/A/1/C/ |
You use cp's -R option to copy directories recursively, as it says in the man page.
|
The wildcard is being expanded before the command line is executed. This yields multiple directory targets as arguments. The cp command can only copy to a single directory at a time. You'd need multiple cp commands to do what you want. You can do this in a shell loop.
|
Happy birthday Nylex!
|
Quote:
|
i tried with -r,this time, its not showing any error, but still the required files couldn't get copied.
|
Quote:
-prune ... read "man find". |
It would probably be better to use a loop.
Code:
for dir in /home/susee/databkp/A/*/C/Code:
for dir in 1 2 3 4; doCode:
mkdir -p /home/susee/datadkp/{1..4}/COne trick is to precede a cp or mv command with "echo" to print out what command would be executed. If it looks good, hit the up arrow and remove the echo. |
Quote:
|
Quote:
source dir: /home/susee/data destination dir : /home/rhl/databkp can you please explain the same with above dirs. and going for other option Code:
for dir in 1 2 3 4....thanks in advance |
Use 'seq' cmd to generate a sequential num list: http://tldp.org/LDP/abs/html/abs-guide.html#EX53
|
It will be helpful to you if you understand how and when the shell expands the * wildcard.
When you create a command line such as: Code:
ls /path/*/stuff/path/1/stuff /path/2/stuff/anything /path/3/stuff/morestuff /path/4/nostuff the shell would expand the * into only the first three items (marked in blue), but not the fourth item (marked in red). The command the shell would actually execute would be: Code:
ls /path/1/stuff /path/2/stuff/anything /path/3/stuff/morestuffThe for loop in jschiwal's response: Code:
for dir in /home/susee/databkp/A/*/C/Code:
for dir in /home/susee/databkp/A/XXX/C/ /home/susee/databkp/A/YYY/C/ /home/susee/databkp/A/ZZZ/C/The problem with your original find command is that you were providing the cp command with too many destination directories. Your command looked essentially like this: Code:
cp source_files targetDir1 targetDir2 ... targetDirNThis is where the loop comes in handy. You copy many source files into one directory, and do it again to the next, etc. Now, your job is to explain what your source paths look like and what your target directories look like. This will help you see the pattern required to create a loop. The code provided to you assumes a simple pattern of names ranging from 1 to 4. |
Dear Mr C,
thanks lot for your outstanding explanation. I've source files at /home/susee/data/network/station/channel/file1 file2 file3 file4...... and destination files at /home/rhl/databkp/network/station/channel/file1 file2 file3...... let us assume file4 is generated today, at the end of the day, i want to copy this file4 from source to destination dir. The "network" is variable, which has values like... A, B, C ,D.... upto some 30 In each network we've it's corresponding station files... like network A contains, A1,A2,A3,A4 network B contains, B1,B2 network C contains, C1,C2,C3,C4,C5,C6 like this we've around 300 station files (from all networks) channel type varies channel1, channel2, channel3 for every station. in that everyday one new file comes. so what i was tyring is, take backup of each file at the end of everyday. i used "for loop" for network variable as it has only 30 values. But Coudn't that go with station, bcoz it has aroud 300 values. this is why i used wild character instead using name. i hope u understood the problem. |
Let's step back a moment. Do you know about rsync ?
|
no,i dont about this "rsync" command
|
| All times are GMT -5. The time now is 12:52 AM. |