Using find -d and copying to the found directories


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Using find -d and copying to the found directories
# 1  
Old 09-07-2009
Using find -d and copying to the found directories

Hi again All Smilie

After posting my first thread just a few eeks ago and having such a great response (Thank You once again Smilie ), I thought I'd perhaps ask the experts again. In short I'm trying to achieve a "find" and "copy" where the find needs to find directories:

Code:
find -d -name outbox

and the copy needs to place a "master" file to these found "outboxes" below the "master" outbox.

I've tried a few variations of:

Code:
find -d -name "outbox" -exec cp $OUTBOX "{}" \;

OR

Code:
find -d -name outbox | while read file; do cp $OUTBOX $file ;done

These though are not working Smilie .. Any ideas how I can effectively copy what's in my "master" outbox to multiple outboxes further down the file tree? Currently I have my script running with absolute paths, but as the folder names between the master outbox and other outboxes can change I'd like to find a clever way of "searching" for outboxes and then copying to them - sound possible?

Thanks in advance and have a super day further.

Regards
Dean
# 2  
Old 09-07-2009
Quote:
Originally Posted by Dean Rotherham
Hi again All Smilie

After posting my first thread just a few eeks ago and having such a great response (Thank You once again Smilie )
You are welcome, although I would really appreciate if you ran the simple test commands I suggested there https://www.unix.com/unix-dummies-que...#post302348379 to figure out what is happening or not on your system.
Quote:
In short I'm trying to achieve a "find" and "copy" where the find needs to find directories:

Code:
find -d -name outbox

and the copy needs to place a "master" file to these found "outboxes" below the "master" outbox.

I've tried a few variations of:

Code:
find -d -name "outbox" -exec cp $OUTBOX "{}" \;

OR

Code:
find -d -name outbox | while read file; do cp $OUTBOX $file ;done

These though are not working Smilie .. Any ideas how I can effectively copy what's in my "master" outbox to multiple outboxes further down the file tree? Currently I have my script running with absolute paths, but as the folder names between the master outbox and other outboxes can change I'd like to find a clever way of "searching" for outboxes and then copying to them - sound possible?
Try this:
Code:
find . -type d -name outbox -exec cp "$OUTBOX" {} \;

By the way, quoting the curly braces is probably unnecessary (despite what an urban legend might suggest) but quoting $OUTBOX might be Smilie
# 3  
Old 09-07-2009
Brilliant .. that now worked ... hummm, not sure why I was battling then. The -type must be the answer Smilie and not -d ... Thanks again.

Regarding the other post, yip it works with the "{}" and NOT without them so I'm as confused as you are? Without the quotes it seems to delete only the first filename within the list given to the command, but when it's in quotes they all get deleted as needed.

Will run the test commands and post my results Smilie

Regards
Dean

---------- Post updated at 04:34 PM ---------- Previous update was at 04:05 PM ----------

sorry to bug you again, but wow I didn't see there were so many posts on the last thread (I didn't get any mails so stopped looking at the thread) .. gosh, sounds like quite a debate was going on .. All in good spirits I hope Smilie ... What can I try run for you? I see many examples of code in the thread but, you made mention of a specific script you'd like me to try, which was that? I'll run and post my results ASAP

Regards
Dean
# 4  
Old 09-07-2009
There are indeed a lot of postings there but the URL I linked to is directly pointing to post #19 where I was asking for three commands to be run on your machine.
# 5  
Old 09-07-2009
Ok, so now I'm really concerned .. this worked? It finds the "test" file WITHOUT the quotes? But why when I'm using the $DELETE file with a list of files to delete it didn't work ... could the fact that it's a list be making any difference? I wouldn't think so .... wow, confusing Smilie I'll see if my script works without quotes and see if it works with multiple files from the $DELETE list. Will post back soon.
# 6  
Old 09-07-2009
Thanks, please post your code and the results to help understanding what you are observing.
# 7  
Old 09-07-2009
Quote:
Will run the test commands and post my results
Please do, we are all interested in this one.

To confirm which O/S you have, please could you post the output from this enquiry:

Code:
uname -a

 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Copying files to directories based on first 6 character

guys, i did create a script but its too long, though it function the same. # cat nightlyscan.sh #!/usr/ksh deyt=`date +"%Y-%m-%d"` for i in `ls -lrt|grep $deyt|awk '{print $9}'` do cp -f $i /S1/Sophos/logger/ done # but i did not paste it all. this is the desired. (9 Replies)
Discussion started by: kenshinhimura
9 Replies

2. UNIX for Dummies Questions & Answers

Copying Directories from one server to another

Hi, I have a requirement where I have to connect to another server and copy directories from one server to another Directories on the Source server look like below (YYYY-MM-DD- 1 to 23) drwxr-xr-x 2 test_user dmfmart 422 Sep 1 23:45 2014-09-01-18 drwxr-xr-x 2 test_user dmfmart ... (3 Replies)
Discussion started by: arunkesi
3 Replies

3. Shell Programming and Scripting

Error check for copying growing directories

I have a simple script which copies directory from one place to another and deleting the source . I am facing a situation when new files gets added when the script has started running. Its resulting in data loss Please suggest a way to avoid data loss. I googled a lot but most are perl... (11 Replies)
Discussion started by: ningy
11 Replies

4. Shell Programming and Scripting

Copying data from files to directories

I have the following that I'd like to do: 1. I have split a file into separate files that I placed into the /tmp directory. These files are named F1 F2 F3 F4. 2. In addition, I have several directories which are alphabetized as dira dirb dirc dird. 3. I'd like to be able to copy F1 F2 F3 F4... (2 Replies)
Discussion started by: newbie2010
2 Replies

5. UNIX for Dummies Questions & Answers

Using grep command to find the pattern of text in all directories and sub-directories.

Hi all, Using grep command, i want to find the pattern of text in all directories and sub-directories. e.g: if i want to search for a pattern named "parmeter", i used the command grep -i "param" ../* is this correct? (1 Reply)
Discussion started by: vinothrajan55
1 Replies

6. Shell Programming and Scripting

Copying all directories while ignoring certain filetypes

I want to write a script that copys over a complete folder including the dirs to another location. However in the process I want to ignore several filetypse that SHOULD NOT get copied over. I know Global Ignore is capable of make the copy command ignore one file type, however I don't know how... (8 Replies)
Discussion started by: pasc
8 Replies

7. Shell Programming and Scripting

How to find 777 permisson is there or not for Directories and sub-directories

Hi All, I am Oracle Apps Tech guy, I have a requirement to find 777 permission is there or not for all Folders and Sub-folders Under APPL_TOP (Folder/directory) with below conditions i) the directory names should start with xx..... (like xxau,xxcfi,xxcca...etc) and exclude the directory... (11 Replies)
Discussion started by: gagan4599
11 Replies

8. Shell Programming and Scripting

Copying a files from a filter list and creating their associated parent directories

Hello all, I'm trying to copy all files within a specified directory to another location based on a find filter of mtime -1 (Solaris OS). The issue that I'm having is that in the destination directory, I want to retain the source directory structure while copying over only the files that have... (4 Replies)
Discussion started by: hunter55
4 Replies

9. UNIX for Dummies Questions & Answers

copying to multiple directories using wildcard

Can we copy a file to multiple directories using a single command line , i tried with * didnt work for me cp /tmp/a.kool /tmp/folder/*/keys/ I am tryn to copy a.kool file to all keys folder in /tmp folder. is something i am missing ? (4 Replies)
Discussion started by: logic0
4 Replies

10. UNIX for Dummies Questions & Answers

Copying multiple directories at the same time using Unix

Another Unix question. How would I copy multiple directories at the same time? Right now I do: cp -r -f /directory1/ ../backup/directory1/ I do that for each directory one at a time. But there are multiple directories I'd like to copy. So instead of sitting there and doing one at a time, is... (9 Replies)
Discussion started by: JPigford
9 Replies
Login or Register to Ask a Question